Should we deprecate comma?
Steven Schveighoffer
schveiguy at yahoo.com
Mon Mar 24 05:32:40 PDT 2014
On Sun, 23 Mar 2014 22:31:25 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> On 3/23/14, 7:21 PM, Kenji Hara wrote:
>> At least I can imagine two reasonable cases.
>>
>> 1. If the code is ported from C/C++, breaking it is not reasonable.
>>
>> 2. If the two expressions are strongly related, using comma operator is
>> reasonable to represent the intensity. I think rather it's an *ability*
>> to represent code meaning by using code style.
>>
>> Kenji Hara
>
> One concession we could make would be to disallow using the result of
> the operator. That might actually catch all bugs discussed herein.
>
> if (condition) ++i, ++j; // fine
> foreach (e; exp1, exp2) {} // ERROR
> if(pMgr->ShouldRecordEvent(eSE_Weapon), pOwnerRaw) // ERROR
> return pMgr->RecordEvent(eSE_Weapon), pOwnerRaw; // ERROR
>
> I think this would be a compromise worth looking into.
In fact, if this was the case, I would use the comma operator more. How
many times I have to change:
if(cond)
exp;
into
if(cond)
{
exp;
exp2;
}
Would be nice to just do:
if(cond)
exp, exp2;
-Steve
More information about the Digitalmars-d
mailing list