Re: Eiffel syntax and the ';'

Curtis Clauson <[email protected]> Sun, 14 Aug 2005 18:35:21 -0700
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Organization The Snake Pit - Development
Message-ID <[email protected]>
alan lamer wrote:

 > i was wondering about the eiffel syntax, that
 > sometimes appears to be confused to me, especially
 > with the use of the ';' character. When is this char
 > really required ?

Historically, people from University backgrounds who design languages 
are very lazy typists and will go to any lengths to eliminate what they 
consider extra or mostly unnecessary characters. The statement-ending 
';' is not needed in most circumstances for the compiler to know when a 
statement ends, but there are still some, like multiple statements on 
one line and your example, where it must be used. It's much like the 
tendency of a student to use one-letter identifiers in example code 
rather than proper self-documenting names. Teacher's bad habits become 
student's bad habits.

 >                x.f
 >                (x+x).f

 > I know that from the parser point of view there might
 > be an ambiguity (to allow the call of the g-like
 > feature in the example) but, as said previously, why
 > the hell using a syntax that leads to such situations.

Here, the compiler is confronted by two possible interpretations:
     x.f;
     (x + x).f;
or  x.f(x + x).f;

While you might think that the compiler ought to be smart enough to know 
the first is what is intended, since the second line of the first is 
valid, the compiler must never assume intention. You might very well 
have intended the second and mis-typed the name of the routine call with 
argument (easy to do with cryptic one-letter names). Compilers will 
always err on the side of caution and throw an error telling you to be 
explicit. This protects you from your own mistakes.

The language syntax does not lead to such situations, rather it allows 
you to use typing and clutter saving syntax in the most common 
situations. The syntax design is a balance between what is easily 
readable for humans and what is efficiently parse-able for the compiler. 
This does not free you from knowing the language well enough to handle 
the uncommon situations. Unfortunately, I've yet to see any 
documentation or course that did not gloss over the uncommon situations 
as not important enough to consider. This is why, to this day, most 
people are not aware that the C "const" modifier only applies to the 
modified reference and not to the object it references.

This situation exists for your example because you are using a source 
shortcut to create an anonymous object "(x + x)" on which you call a 
routine. If you choose to use such shortcuts you must be ready to handle 
the possible resulting uncommon situations, like an explicit statement 
terminator.

As the chicken said to the lion:
    "You knew the job was dangerous when you took it Phred."

-- 
--------------------------------------------------------
The Snake Pit - Development   www.TheSnakePitDev.com
Curtis Clauson                [email protected]
Proprietor

"Any sufficiently over-complicated magic is indistinguishable from 
technology." -- Llelan D.