Comma operator = broken design

Alex Rønne Petersen xtzgzorex at gmail.com
Wed Dec 7 08:49:33 PST 2011


Hi,

Consider this code:

if (condition)
     foo();
else
     bar(),

baz();

Notice the comma in the bar call. This will actually compile. Why? 
Because the program is really interpreted as:

if (condition)
{
     foo();
}
else
{
     bar();
     baz();
}

This is, honestly, ridiculous. On most European keyboard layouts, comma 
is on the same key as semicolon. This means that a typo such as the 
above can lead to an incorrect (but compiling) program easily, rather 
than a compile-time error.

I really do not see the value in allowing such syntax in the first 
place. I've been told that one argument was that generated code might 
use it, but I have no idea why it would be needed. Furthermore, this 
operator makes it very hard to introduce Python-style tuples in the 
language.

Why is this operator still kept around?

- Alex


More information about the Digitalmars-d mailing list