why ; ?

Leandro Lucarella llucax at gmail.com
Mon May 12 09:42:29 PDT 2008


Janice Caron, el  9 de mayo a las 05:42 me escribiste:
> I'm not sure there's anything further to say, however. The reason is,
> when you said "Yes, in my suggestion you need to escape
> false-newline-end-of-statement", you effectively closed all
> ambiguities. My arguments were predicated on the assumption that there
> would be no newline-escaping. That means, your plan /is/ workable -
> but the price (having to escape newlines) is higher than I want to
> pay. It becomes a matter of taste. I prefer C-style; you prefer
> Python-style. Maybe you (or someone else who wants this) can write
> that conversion tool I mentioned somewhere.

I don't think it's entirely a matter of taste. It saves typing and thus
makes the code more readable and easier to maintain. Is like saying "auto"
it's just a matter of taste, and you say "auto" is bad because we should
always have the redundancy of the type declaration.

> But even with the "you need to escape escape
> false-newline-end-of-statement" rule, there is still room for silent
> bugs to creep in. For example:
> 
>     foo(int x)  // Danger!
>     {
>         /* stuff */
>     }

Is this valid D?

> Under your scheme that would have to be rewritten as either
> 
>     foo(int x)  {
>         /* stuff */
>     }
> 
> or
> 
>     foo(int x)  \
>     {
>         /* stuff */
>     }
> 
> or else run the risk of being misparsed as
> 
>     foo(int x);
>     {
>         /* stuff */
>     }
> 
> which often times will be valid D. (Not always, but sometimes - e.g.
> as an inner function). So unless you go "all the way" and aim for full
> Python style, you run the risk of introducing some very hard to find
> bugs.

I don't think that's valid D anyway, but I'll assume you meant:
void foo(int x)
{
    /* stuff */
}

If this is the case, the parser should expect a function definition after
a function declaration (since function declaration are not *that* usual in
D, I think is the better way to go).

So, for a function declaration and a new block of code you write:
void foo(int x); // ; is mandatory for function declaration
{
    // new block
}

For function definition, you just type:
void foo(int x)
{
    /* stuff */
}


BTW, I know this will never make it into D, I just don't think you have
the right reasons. I think the only valid reason to not do it (and a very
big one) is that D wants to be in the C-like syntax family, so it *wants*
to look like C. The ambiguities, redundancy and supposed hidden bugs are
all very weak reasons IMHO...

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
EL PRIMER MONITO DEL MILENIO...
	-- Crónica TV



More information about the Digitalmars-d mailing list