Stylistic red pen time!
On 2012-04-17 23:44:14 +0000, Peter Olcott said:
> Boolean Halts(String tm, String input)
> {
> if tm halts on input
> // tm is a valid TM and halting is decidable
Inconsistent indentation (the 'if' is indented by three spaces; the
comment by a further two spaces).
> return true;
> else // anything else, such as not decidable,
> return false; // not a valid TM, not halting
Inconsistent indentation (now the second level of indentation is only
one space).
> }
>
> // DecidabilityDecider
Function comment reiterates the function name without adding any information.
> Boolean Decidable(String tm, String input)
> {
> if (Halts(tm, input))
> return true;
> else
> return false;
Inconsistent indentation again.
> }
Statement groups of the form 'if (x) return true; else return false;'
can be replaced with 'return x;' in every language with a boolean type.
The 'if' version is longer without adding clarity or meaning.
More generally, the 'Decidable' function is exactly the 'Halts'
function and could be removed entirely. If you really think 'Halts'
needs two names, use a simpler implementation that passes the
parameters and return value straight through to and from Halts, or use
whatever facility your language provides for aliasing (function
pointers, delegates, preprocessor shenanigans, or whatever).
> M( String Input )
M has no return type, inconsistent with other functions in your typed,
C-like pseudolanguage. This is done without explanation. If your
language has (typeless) procedures, that's unusual enough to deserve
mention.
Whitespace use here is inconsistent with the rest of your code.
M's parameters are capitalized, but every other function's parameters
are strictly lowercase.
> {
> if ( Decidable( Input, Input ) )
No leading indentation for the statements within this function, unlike
every other function.
Whitespace use here is inconsistent with the rest of your code.
> Loop Forever;
An unexplained lapse into natural language for a very simple element of
your program.
> else
> Exit;
Given the more obviously natural-language use of "Loop Forever" above,
is "Exit" meant to be a symbol in your language such as a call to a
procedure or a special statement, or is it meant to be a prose
description of that branch of the program's behaviour (which would be
odd, since you already used 'return' above to exit from functions)?
Clarify.
> }
>
> Decidable(M, M); // Correctly returns False.
Are whatever values that bare function names evaluate to in your C-like
pseudolanguage implicitly convertible to meaningful String values?
Shouldn't you spell that out more explicitly, given how badly it
violates the principle of least surprise? Alternately, this line is
missing some conversions.
This pseudocode is incredibly sloppy and it points to a lot of bad
habits. Those habits will lead to confusing, hard-to-follow code and
confusing, hard-to-reason-about systems. If you write real code like
this, please, take some pride in your work and clean it up, then keep
it clean as you revise it.
I'm not even going to go into the gaping logical problems in your
pseudocode or in your choice of names. George is already doing a great
job of yelling at you about that.
-o
(Do you even *have* a habitual coding style?)