Comma operator = broken design

Nick Sabalausky a at a.a
Wed Dec 7 10:19:31 PST 2011


"Robert Jacques" <sandford at jhu.edu> wrote in message 
news:op.v54q04vd26stm6 at sandford.myhome.westell.com...
> On Wed, 07 Dec 2011 11:49:33 -0500, Alex Rønne Petersen 
> <xtzgzorex at gmail.com> wrote:
>>
>> Why is this operator still kept around?
>
> Take your pick:
> 1) So that legacy B/C/C++/D1/etc code can be trivially ported to D1/D2.

That's a pretty weak counter-argument:

A. I'd think a lot of C/C++ code can't be trivially ported to D anyway.
B. "B", seriously? ;)
C. Being able to link to C/C++ makes it less likely to need to port C/C++ 
code anyway.
D. Outside of for loops (special-case-able), comma operator is rarely used 
in C/C++/D.
E. Even among actual uses of the comma operator, I think it'd be rare (if 
even possible) to have a use of it that isn't trivially convertable to 
non-comma.

> 2) The comma operator is heavily used in regular old for loops.

That can be special cased.

> 3) It is frequently used internally by the compiler to effect syntactic 
> lowerings. A decent portion of D's syntax is not transformed directly to 
> instructions; instead it is converted to simpler code which is in turn 
> processed. Technically the compiler doesn't need ',' in the language to do 
> this.

Like you're saying, it can exist in the compiler's internal AST without 
having to exist in the parser.

> 4) D has a policy of 'If C/C++ code compiles in D without error, it must 
> have the same syntactic meaning as in C.' So even if we remove the comma 
> operator, we might not get comma-style tuples. (I don't know if anyone has 
> looked at this issue in depth)

Meh, I still think it would be better to allow such situations on occasion 
and just provide a "--c-lint" switch to warn (or error) on any such code. 
Porting C/C++ to D is a much smaller use case than writing/maintaining D. I 
don't think it's a good idea to hamper the langauge for the sake of such an 
edge case when it's just as possible to simply handle that scenario with a 
special tool/switch. But I guess I'm outvoted by Walter on that :(

> 5) The comma and semicolon are on different keys on US style keyboards.
> 6) It is trivial to change your keyboard layout (I've hotkeyed Greek for 
> fast math symbols)

Those are very weak counter-arguments.

> 7) We are trying to stabilize the language, so massive code-breaks are 
> frowned upon.
>

Poo ;(

> Personally, I think real tuples outweigh the comma-operator, but real 
> tuples don't necessarily need the ',' (we could use '..' or something else 
> instead) and removing comma-expressions isn't without its problems.
>
> P.S. I was going to suggest testing/looking into issue 4, but a quick test 
> in D suggests that there are valid ',' and '(,)' style expressions in 
> C/C++ that would remain valid in D with comma-tuples. 




More information about the Digitalmars-d mailing list