The Comma Operator's Deprecation Can't Come Soon Enough
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 15 09:57:49 PDT 2014
Jane Doe:
> So, you wanna nerf everything that could produce the wrong
> behavior?
A smarter question is: How to reduce the number of bugs in D code
decreasing the language functionality only very little, and
keeping the language handy (or making it even more handy)?
> There is nothing in this example that shows the comma operator
> is evil.
Typeof takes an argument, but two were given:
typeof(R.init.front, depth - 1)
The fact that in truth only one argument was given is caused by
the comma operator that has both the semantics of sequence (when
you define multiple variables, multiple enum items, multiple
function arguments, multiple template arguments, and so on), and
the not often useful semantics of sequencing of expressions with
side effects, plus keeping the result of the last one.
If you restrict the usage of commas, disallowing that second
semantics, that code causes a compilation error.
The idea of killing the comma operator was discussed at length in
past threads. I suggest to deprecate it, and eventually open the
syntax to better usages (tuples and pattern matching, making D
quite more handy than now).
Bye,
bearophile
More information about the Digitalmars-d
mailing list