Comma operator = broken design

Timon Gehr timon.gehr at gmx.ch
Fri Dec 9 05:01:12 PST 2011


On 12/09/2011 01:11 PM, Regan Heath wrote:
> On Fri, 09 Dec 2011 12:00:57 -0000, Timon Gehr <timon.gehr at gmx.ch> wrote:
>> On 12/09/2011 10:26 AM, Jonathan M Davis wrote:
>>> On Friday, December 09, 2011 10:19:18 Don wrote:
>>>> Are there any cases where you're using comma outside of for loops?
>>>> I wonder how much would break if were made illegal everywhere else.
>>>
>>> I'm sure that it would break code, but most people consider it bad
>>> practice to
>>> use the comma operator for much outside of for loops.
>>
>> 'most people'?
>
> Yes, I would guess that you're in the minority here.
>

'most people' do not care about this discussion, so lets stop it. :o)

What I wanted to say is just that throwing in 'most people' does not 
help an argument, because a) there is no evidence and b) 'most people' 
are in general just as often (or even more) wrong than 'a few people'.

>>> Occasionally, it's
>>> useful to use one in an expression, but on the whole, it's just
>>> confusing and
>>> error-prone.
>>
>> It is confusing to people who don't know the language. It is a simple
>> construct. In my experience, it is certainly not error prone. If you
>> are aware that such an operator exists.
>
> It's error prone in cases where you use it without realising, as in the
> example I posted.
>

That is true for every language construct.

>>> The resulting code may not be as compact, but it
>>> wouldn't be hard to write.
>>
>> It would be a PITA in some cases.
>
> Really? Give us an example where not having comma makes things
> significantly difficult.

I already agreed that rewriting the code is trivial. It is just that I 
usually do not want to spend lots of my time on trivial stuff.

>
>>> And unless you're dealing with a programmer who
>>> uses it uncommonly often, not much code is going to break.
>>
>> I _am_ such a programmer.
>
> So it seems :)

If you carefully read my posts you will find that I did never say that I 
am against removing the comma operator.

I would like comma to have tuple semantics. Comma should keep
its precedence level and then work like this:

if(foo) bar, baz, qux; // the value of the tuple is unused, so no change 
in semantics

if(bar()||(foo(), *++p==(*++x)++)[1]){} // the value is used, so an 
explicit index is necessary

It would make the language more consistent because the comma in 
expressions would be the same comma as the one that is used elsewhere.

That is against the C compatibility rule though, and it would in some 
cases silently break code.

> I don't want to make your life harder but I think this
> change would make life easier for a large number of people, a small
> amount of the time. The equation is unbalanced in favour of it's
> removal, IMO.
>

This part of your post is somewhat contradictory.




More information about the Digitalmars-d mailing list