The Comma Operator's Deprecation Can't Come Soon Enough

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 15 11:16:11 PDT 2014


On Tue, Jul 15, 2014 at 05:26:11PM +0000, Tofu Ninja via Digitalmars-d wrote:
> On Tuesday, 15 July 2014 at 17:09:14 UTC, H. S. Teoh via Digitalmars-d
> wrote:
> >On Tue, Jul 15, 2014 at 04:52:34PM +0000, Israel Rodriguez via
> >Digitalmars-d wrote:
> >[...]
> >>Nuh uh...The comma operator is too valuable to loose...
> >
> >Please cite an example where it is "valuable"?
> >
> >
> >T
> 
> Yes please, I legitimately can't think of any use case. I don't
> understand why was this was ever introduced to D? What is the use?

I don't think it was "introduced", probably just inherited from C.

The traditional justification for it in C is to allow writing things
like:

	for (i=0, j=0; i < 10 && j < 20; i++, j+=2) {
		...
	}

However, this can be easily implemented as special syntax for for-loops;
it needn't be a general syntax that can be used everywhere.

There are some other marginal use cases where it saves a tiny bit of
typing, but really, in this day and age, the only time that's really
*needed* is when submitting entries to the IOCCC. :-P

Of course, then C++ came along and made the whole thing a whole order of
magnitude worse, by introducing operator,(), which leads to nastiness
like:

	void func(Array<2,int> matrix) {
		matrix = 1, 2, 3,
			 4, 5, 6,
			 7, 8, 9;
	}

which looks cool until you think about it some more, and then you
realize that there are just so many ways in which this can go really,
horribly wrong.

Personally, I can't wait for the comma operator to be killed off for
good. Preferably with extreme prejudice.


T

-- 
Try to keep an open mind, but not so open your brain falls out. -- theboz


More information about the Digitalmars-d mailing list