Comma operator = broken design
bearophile
bearophileHUGS at lycos.com
Fri Dec 9 04:09:35 PST 2011
Timon Gehr:
> 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);
It's ugly code worth fixing/rewriting. If I see something like that in production code, I always burn it with fire and rewrite it.
Turning such usages of comma operator into syntax errors looks like a general improvement for D.
Bye,
bearophile
More information about the Digitalmars-d
mailing list