www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: why ; ?

reply bearophile <bearophileHUGS lycos.com> writes:
Pragma:
 ECMAScript (JavaScript) allows this by making the terminating ';' optional, 
but you wind up with occasionally hard-to-find ambiguities as a result.  You
wind up falling back on using ';' everywhere as a habit just to avoid that
problem.

Can someone show me few examples of such ambiguities? (In about ten thousands lines of D code I have written I think there are very few (or maybe none) of them...). Bye, bearophile
May 07 2008
parent reply Pragma <eric.t.anderton gmail.com> writes:
bearophile Wrote:

 Pragma:
 ECMAScript (JavaScript) allows this by making the terminating ';' optional, 
but you wind up with occasionally hard-to-find ambiguities as a result.  You
wind up falling back on using ';' everywhere as a habit just to avoid that
problem.

Can someone show me few examples of such ambiguities? (In about ten thousands lines of D code I have written I think there are very few (or maybe none) of them...).

Sure. // given: void foo(){} void bar(){} // call both functions without a terminating ';' foo bar The parser would likely interpret this as a variable declaration for "bar of type foo". However it's also just as valid as the intent: two consecutive calls to functions w/o the "()" hint. Not only is this difficult for the compiler to parse correctly (it lexes just fine), but it's just as hard for the developer to validate. Having little things like semicolons help alleviate those issues without complicating the compiler, or making the developer's job more cumbersome. In practice, I'd imagine that these kinds of things would happen infrequently, but then again that's also the reigning theory about deliberately writing buggy code. ;) - Pragma
May 07 2008
parent terranium <spam here.lot> writes:
Pragma Wrote:

 // call both functions without a terminating ';' 
 foo bar
 
 The parser would likely interpret this as a variable declaration for "bar of
type foo".

:) you can't declare a variable of certain type in ecmascript.
May 08 2008