Dimensionality of program code (was: Exceptional coding style)
Era Scarecrow
rtcvb32 at yahoo.com
Thu Jan 17 14:01:24 PST 2013
On Thursday, 17 January 2013 at 20:17:06 UTC, Stewart Gordon
wrote:
> And in most languages, a program/module is essentially just a
> sequence of tokens, and as such is one-dimensional. We might
> look at it in a two-dimensional form, but this two-dimensional
> layout means nothing as far as the program structure and
> semantics are concerned. And again, you could think of it as a
> curve, passing from the beginning of each line to the end and
> then to the beginning of the next line.
As I recall for the compilers very early on, all comments and
unneeded whitespace were simply removed before compiling, leaving
you with one very long command string. The /**/ comment syntax
makes perfect sense in this case; Later tools more memory and
hardware power make it more manageable; but // requires 2d code
to properly compile until the comments are stripped.
// c example, originally isprime and main don't have
// return types, defaulting to int instead.
int isprime(int n){int cnt=2;if(n<2)return
0;for(;cnt<n;cnt++)if((n%cnt)==0)return 0;return 1;}int
main(){int cnt=2;for(;cnt<1000000;cnt++)if
(isprime(cnt))printf("%d \n", cnt);}
It's one of the reasons the syntax requires a semicolon after
each statement so it can tell obviously where something ends.
More information about the Digitalmars-d
mailing list