Tuple DIP

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Feb 16 20:48:30 UTC 2018


On Fri, Feb 16, 2018 at 01:16:13PM -0700, Jonathan M Davis via Digitalmars-d wrote:
> On Friday, February 16, 2018 21:01:02 Martin Nowak via Digitalmars-d wrote:
> > On 01/14/2018 12:21 AM, Timon Gehr wrote:
> > >> what would be the equivalent of this ?
> > >> ` writeln(tuple!("x", "y", "z")(2, 3, 4).y); `
> > >
> > > It would continue to work the same way.
> > >
> > > I did consider adding a proposal for built-in named tuple syntax:
> > >
> > > writeln((x: 2, y: 3, z: 4).y);
> > >
> > > (int a, double b) t = (a: 1, b: 2.0);
> > > int x = t.a;
> > > double y = t.b;
> >
> > Tuples are anonymous bundles, when you want a product type with
> > field names use a struct.
> 
> That's not necessarily unreasonable, but std.typecons.Tuple is frequently
> used as a convenient way to return a group of values, and the trend has been
> towards using named values, because those are easier to deal with as return
> values, because they're somewhat self-documenting at that point, and they're
> less error-prone. So, if we're talking about adding more complete tuples to
> the language, if they don't have support for names, you then have the
> problem of whether it's better to use the built-in tuples or something like
> std.typecons.Tuple with named values, and there's a pretty strong argument
> at that point that it's better to use the named tuples and lose whatever
> benefits the built-in tuples might provide, because the named tuples result
> in more maintainable code.
[...]

Tuples with named fields are essentially anonymous structs.  If we had
those, 60% of what this DIP addresses would already have been solved.
Cf.:

	https://forum.dlang.org/post/kfbnuc$1cro$1@digitalmars.com


T

-- 
Ignorance is bliss... until you suffer the consequences!


More information about the Digitalmars-d mailing list