Should we deprecate comma?
Marc Schütz" <schuetzm at gmx.net>
Marc Schütz" <schuetzm at gmx.net>
Mon Mar 24 05:10:38 PDT 2014
On Monday, 24 March 2014 at 01:28:02 UTC, Kenji Hara wrote:
> I'm partially against to it.
>
> 1. I think removing comma operator does not have useful effect
> for tuple
> syntax discussion. For example:
>
> 1a. If you want to use parenthesis syntax (...) for tuple,
> we should
> resolve one-element tuple ambiguity first.
> (exp) // one-element tuple, or just an expression ?
> And, removing comma operator does not resolve this issue.
I believe this is a non-issue. From a language-users POV, there
should be no difference between a one-element tuple and an
expression, thus there's no need to distinguish the two. (The
actual implementation in the compiler may of course treat them
differently.)
>
> 1b. If you choose other syntax for tuple, comma operator
> will be no
> longer related to tuple syntax discussion.
> {exp, exp2} // eg. using brace for tuple syntax no
> longer touch to
> comma operator
>
I'd prefer parentheses, but that's bike-shedding, of course. In
any case, it's better to have some freedom in choosing the final
syntax, rather than being forced to use one that is less
well-liked/intuitive.
> 2. Indeed in some case comma operator is bug-prone, but if it
> is used
> directly on the ExpStatement, it's still useful to me.
>
> foreach (e; exp1, exp2) {} // maybe bug?
> if (cond) exp1, exp2; // in most case, this is not a bug.
>
> So, completely removing comma operator will cause negative
> affect in
> some cases.
IMO this is bad style. It only saves a few characters, but
hampers readability. The example with the assert() and the
ternary operator that someone else gave is much more relevant,
however, as it's somewhat harder to rewrite (need to resort to a
lambda literal, or rewrite as statements).
More information about the Digitalmars-d
mailing list