Comma operator = broken design

Don nospam at nospam.com
Fri Dec 9 01:19:18 PST 2011


On 08.12.2011 20:22, Timon Gehr wrote:
> On 12/08/2011 05:02 PM, Regan Heath wrote:
>> On Thu, 08 Dec 2011 12:17:20 -0000, so <so at so.so> wrote:
>>
>>> On Thu, 08 Dec 2011 11:17:48 +0200, Dejan Lekic
>>> <dejan.lekic at gmail.com> wrote:
>>>
>>>>
>>>>>
>>>>> Why is this operator still kept around?
>>>>
>>>> No offense, but I find it strange/funny that you even ask why! :)
>>>>
>>>> Have you never used comma in for loops???
>>>>
>>>
>>> Not sure if it is that relevant for D, but good point.
>>>
>>> for(auto i=beg(), e=end(); i!=e; ++i)
>>> for(auto i, j, k;; ++i, ++k)
>>> ...
>>
>> It's kinda amusing that this thread appeared just as we had a case of
>> this here at work. The developer accidentally coded something like...
>>
>> if (function(..), FALSE)
>> {
>> }
>>
>> Accidentally adding the ", FALSE" /after/ the ) instead of as a new
>> parameter to the function.
>>
>> (note; This was in C++ with default parameter values so the function can
>> in fact take 1-4 args).
>>
>> When I pointed this out, he said "how does that even compile" and was
>> completely unaware of the existence of the comma operator, nor (once I
>> explained it) did he realise it was in any way related to the comma used
>> in for loops. People simply don't think of them as being the same thing
>> at all. Instead, people learn the comma syntax as a special
>> characteristic of the for loop, and use it nowhere else.
>>
>> I think the comma operator is of little benefit (except where used in a
>> for loop) and it is a source of bugs and we'd be better off without it.
>> Even if it means porting C/C++ requires modification, or existing D (I
>> doubt very much of it) breaks.
>>
>
> Phobos would break, for example. And some of my code too.

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.


More information about the Digitalmars-d mailing list