Killing the comma operator
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Tue May 10 05:49:28 PDT 2016
On 5/10/16 6:13 AM, Andrei Alexandrescu wrote:
> On 5/10/16 1:09 PM, Andrei Alexandrescu wrote:
>> On 5/10/16 12:52 PM, Mathias Lang wrote:
>>> So, following DConf2016, I raised a P.R. to deprecate usage of the comma
>>> expressions, except within `for` loops increment [5].
>>
>> The agreed-upon ideea was to allow uses that don't use the result
>> (including for loops). No? -- Andrei
>
> In fact I thought that got implemented a while ago, that's why I didn't
> insist much lately. -- Andrei
It was never pulled. In fact, Marc Schütz just closed his PR when he
found Mathias' PR.
https://github.com/dlang/dmd/pull/5737#issuecomment-217946868
Note, there was some pretty good examples of (ab)use of the comma
operator in one of those:
https://github.com/dlang/dmd/pull/3399#issuecomment-38401339
For my input, I say kill it with fire, but only after deprecation :)
When you see the kinds of bugs this has caused, it's horrifying.
I agree with your proposed solution (and so does Daniel Murphy BTW).
Sadly, I don't know if true tuple support can be had anytime soon, we
may need to wait a long time for that.
BTW, has anyone proposed a replacement like this?
auto ref comma(T...)(auto ref T t) if(T.length > 1)
{
return t[$-1];
}
Sure seems doable without a language feature. Just replace x, y with
comma(x, y).
On 5/10/16 5:52 AM, Mathias Lang wrote:
> As documented in TDPL (thanks @schveiguy) [2].
I can't take credit for this, Ali pointed it out to me after his talk
when I pointed out the problem during the talk. He said something along
the lines of "I knew I had not made this up and had seen it somewhere!"
-Steve
More information about the Digitalmars-d
mailing list