Should we deprecate comma?

Etienne Cimon etcimon at gmail.com
Sun Mar 23 20:22:56 PDT 2014


On 2014-03-23 22:31, Andrei Alexandrescu 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.
>
>
> Andrei
>

How about allowing it only inside parenthesis?

e.g.


if(pMgr->ShouldRecordEvent(eSE_Weapon), pOwnerRaw) // ERROR
return pMgr->RecordEvent(eSE_Weapon), pOwnerRaw; // ERROR
if((pMgr->ShouldRecordEvent(eSE_Weapon), pOwnerRaw)) // OK
return (pMgr->RecordEvent(eSE_Weapon), pOwnerRaw); // OK




More information about the Digitalmars-d mailing list