Statement terminators
Jim Giles
jlg at lanl.gov
Tue May 9 08:09:59 AEST 1989
>From article <2296 at mit-caf.MIT.EDU>, by vlcek at mit-caf.MIT.EDU (Jim Vlcek):
> You see, we have to _read_ the source code we write, and having extra
> characters in the source to escape newlines adds clutter which impedes
> one's recognition of the source text. Consider: in normal printed
> text, a carriage return is simple whitespace. Why should it be
> different in source code?
It should be different in source code because programming is a _different_
process than generating normal printed text (or do you also start every
program statement with a capital letter, etc?). I'm glad _I_ don't have
to read your source code. I _REALLY_HATE_ it when somebody squashes all
their source together.
> And imagine this
> Everytime one starts a new statement, one must insert a carriage\
> return
> No matter how short it is
> No matter how annoying that gets
> Get the point?
And imagine this: somebody writing code the way Jim Vlcek is recommending-
printd(n) /* print n in decimal*/ int n; if (n<0) {putchar('-');n=
-n;} i=0; do {s[i++]=n%10+'0'; /* get next char */ } while ((n/=10)
>0); /* discard it */ while (--i >= 0) putchar(s[i]);} printd(n) /*
print n in decimal (recursive) */ int n; {int i; if (n<0) {putchar
('-'); n= -n;} if ((i=n/10) !=0) printd(i); putchar(n%10+'0');}
Get the point? _NOBODY_ writes _PROGRAMS_ this way. _EVERYBODY_ uses the
end-of-line as _MORE_ than _just_ whitespace. In fact, almost everyone
begins each program statement on a separate line. The design criterion
of relevance here is that the most common usage should have the simplest
syntax - that is, let the end-of-line be a statement terminator (keep
semicolon also, this allows multiple statements per line if desired).
The _less_ common usage (by a _long_ shot) is continuation of statements
across lines - it is _this_ case that should have the extra syntax of
an escaped carriage return. The extra syntax is _not_ clutter, it serves
to point out explicitly the unusual occurrance of a continued line.
(Program above was both examples from page 85 of K&R.)
More information about the Comp.lang.c
mailing list