Comma operator = broken design

Regan Heath regan at netmail.co.nz
Fri Dec 9 04:06:39 PST 2011


On Fri, 09 Dec 2011 11:39:55 -0000, Timon Gehr <timon.gehr at gmx.ch> wrote:
> On 12/09/2011 10:19 AM, Don wrote:
>> On 08.12.2011 20:22, Timon Gehr wrote:
>>> Phobos would break, for example. And some of my code too.
>>
>> Are there any cases where you're using comma outside of for loops?
>
> Yes, one for every 65 LOC.
>
>> I wonder how much would break if were made illegal everywhere else.
>
> These are the occurences of the comma operator in directory 'std':
>
> return r2.empty ? (r1 = r, true) : false;
> return binaryFun!pred(r.front, e) ? (r.popFront(), true) : false;
>
> if (f.flPlus)
>      signChar = '+', ++minw;
> else if (f.flSpace)
>      signChar = ' ', ++minw;
>
> if (std.ascii.toLower(p.front) == 'n' &&
>         (p.popFront(), std.ascii.toLower(p.front) == 'f') &&
>         (p.popFront(), p.empty))
>
> enforce((p.popFront(), !p.empty && std.ascii.toUpper(p.front) == 'A')
>          && (p.popFront(), !p.empty && std.ascii.toUpper(p.front) ==  
> 'N'),
>         new ConvException("error converting input to floating point"));
>
> if (indexStart != 0)
>      formatValue(w, indexStart, f), put(w, '$');
>
> if (c == '\"' || c == '\\')
>      put(w, '\\'), put(w, c);
> else
>      put(w, c);
>
> return (++mi.m_cRefs, cast(HXModule)mi);
> return (++mi.m_cRefs, hModule);
>
> return
>      c <= 0x7F ? 1
>      : c <= 0x7FF ? 2
>      : c <= 0xFFFF ? 3
>      : c <= 0x10FFFF ? 4
>      : (assert(false), 6);

All of the above could be improved with the removal of the comma operator,  
IMO.  They are needlessly complicated/confusing with it.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list