Should the comma operator be removed in D2?

dsimcha dsimcha at yahoo.com
Mon Nov 16 20:48:02 PST 2009


== Quote from Robert Jacques (sandford at jhu.edu)'s article
> On Mon, 16 Nov 2009 17:53:45 -0500, Stewart Gordon <smjg_1998 at yahoo.com>
> wrote:
> > dsimcha wrote:
> > <snip>
> >> Axe.  Looks like the only things it's good for are making code
> >> undreadable and
> >> abusing for loop syntax to...
> >>  Make code unreadable.
> > <snip>
> >
> > Suppose you want the increment of a for loop to change two variables in
> > parallel.  I don't call that making code unreadable.
> >
> > Stewart.
> Yes the classic use case of the comma operator is multi-variable
> declarations/increments in a for loop.

But in D we have the scope statement that makes incrementing multiple variables
trivial even in the presence of breaks and continues:

for(size_t i = 0; i <= 10; i++) {
    scope(exit) otherVariable++;
}

It would be one thing if the comma operator were an innocent feature that wasn't
hurting anything, but it uses up a very nice piece of syntax on something that
usually serves to make code much less readable.



More information about the Digitalmars-d mailing list