Should we deprecate comma?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Mar 24 07:48:13 PDT 2014


On Mon, Mar 24, 2014 at 01:13:51PM +0000, Dicebot wrote:
> On Monday, 24 March 2014 at 13:12:36 UTC, Dicebot wrote:
> >If you are not ready to break the code for it, there is nothing to
> >discuss. It is not something to compromise about - either kill it
> >completely, or just let it be. Anything else will make things only
> >worse.
> 
> And yes, no one so far has presented a code case where using comma
> expression is legitimate and not just trying to save few keystrokes by
> confusing the hell out of everyone else.

I vote to kill the comma operator.

The only actual legit use case I've seen so far is inside a for-loop,
where IMO the syntax should just be special-cased. All other uses
brought up so far fail to convince me about their merit -- they can all
be rewritten in a style that's more readable, less error-prone, and more
maintainable.  The objections all amount to "Oh no! You mean I have to
actually type 2 extra brace characters to write code in the bad style
I'm habitually used to writing?!", and "Oh no! I have to actually split
up my multiple statements into actual multiple statements which is
actually more readable for the poor sods who will have to maintain this
code after I leave?!", both which utterly fail to convince me.

The only "indispensible" use of the comma operator that I've seen in my
entire career is in IOCCC entries, where the whole point is to make the
code obscure and non-obvious.

Not to mention, the fact that some people have been asking about whether
"int x,y" will continue to be valid syntax shows that very few people
even understand what the comma operator *is*, much less its subtle
semantics, which is another strong sign that we should kill it with
extreme prejudice. Of all the bad design decisions made in C and C++,
the comma operator must be the most blatant one that D failed to shed.
Kill it, I say.


T

-- 
People who are more than casually interested in computers should have at
least some idea of what the underlying hardware is like. Otherwise the
programs they write will be pretty weird. -- D. Knuth


More information about the Digitalmars-d mailing list