On Monday, 24 March 2014 at 02:31:46 UTC, 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.
I like it a lot. Almost *all* the "abusive" uses of "operator
comma" I've seen use this trait of operator comma. So this would
kill those:
//----
auto a = fun(), 5; //WTF is wrong with you?
//----
On the other hand, the "legit" cases of comma never seem to use
the return value. The "only" execute two statements in a single
context. For example:
//----
for (size_t i, j ; someCondition() ; ++i, ++j )
{...}
//----
I think this is *the* single most common use of operator comma,
and I also think it is perfectly legit. Sure, it can easily be
migrated away from, but I think it would be gratuitous breakage
of good code.
--------
So this has my +1 vote.