[comp.compilers] Semicolons as separator/terminator

bron@SGI.COM (Bron Campbell Nelson) (09/08/90)

Since everyone seems to be throwing their $0.02 coding tricks into
this discussion, I thought I'd toss in mine.

I never liked the semicolon as a separator, so I simply adopted a
coding style that allowed me to treat the semicolon as a terminator.
Every Pascal compiler I've ever worked with *allows* one to have null
statements (e.g. put a semicolon before an "end" statement).  So by
simply always using begin/end blocks even for single statements (which
is probably a good idea in any event), you can just terminate each
statement with a semicolon. e.g.
	while b1 do begin
	    s1;
	end;
You can even put a semicolon after the "begin" if you want, though I
never did.  The only place you get into trouble is with the "else"
clause of an "if" statment, since you cannot have a semicolon
before an "else."  So I just used:
	if c1 then begin
	    s1;
	end else begin
	    s2;
	end;
Admittedly, the "end else begin" part looks a bit funny, but is it
easy to get used to, and in my opinion looks less funny than putting
the semicolon in front of the statement (which other writers have
suggested).  This also has the advantage that the same coding style
can be used in other languages (e.g. C), making it easier to switch
back and forth.

--
Bron Campbell Nelson
bron@sgi.com  or possibly  ..!ames!sgi!bron
-- 
Send compilers articles to compilers@esegue.segue.boston.ma.us
{ima | spdcc | world}!esegue.  Meta-mail to compilers-request@esegue.