Comma expressions must die [Was: Reddit: why aren't people using D?]

Leandro Lucarella llucax at gmail.com
Fri Jul 24 08:30:23 PDT 2009


Adam D. Ruppe, el 23 de julio a las 22:56 me escribiste:
> On Fri, Jul 24, 2009 at 01:38:30AM +0000, Jesse Phillips wrote:
> > Thanks for the tutorial, expect to see it on Wiki4D within a year :D
> 
> This actually doesn't /quite/ work, since the tuple returned by tuple() has
> unnamed fields, which is a different type than the one with named fields.
> 
> Gah.
> 
> This works though:
> 
> auto getPoint() { return Tuple!(int, "x", int, "y")(5, 2); }
> 
> That's getting a wee bit ugly even for my likes, but is the best way for
> correctness and ease of use on the calling end. Or
> 
> Tuple!(int, int) getPoint() { return tuple(5,2); }
> 
> That works, but then you have to address the return value as:
> 
> auto p = getPoint();
> p.field[0] == 5
> p.field[1] == 2
> 
> 
> Still, easy enough to say:
> 
> auto x = p.field[0]; auto y = p.field[1];
> x == 5
> y == 2

And you still think that's not remarkably worse than something like:

(int, int) getPoint() { return (5, 2); }
auto (x, y) = getPoint();

I really think that's the difference between happily using tuples or curse
them for the rest of your life :)

I don't think comma expressions should be used for tuples (I don't care
much either), but you can add support to the language without breaking
them using something like @(1, 2, 3) or ![ 1, 2, 3 ] or whatever.

But you should support multple assignment, for example. If you don't, you
don't have real tuple support, just a toy tuple emulation.

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
We're rotten fruit
We're damaged goods
What the hell, we've got nothing more to lose
One gust and we will probably crumble
We're backdrifters



More information about the Digitalmars-d mailing list