Tuple DIP
Timon Gehr
timon.gehr at gmx.ch
Sat Feb 17 04:45:54 UTC 2018
On 16.02.2018 21:16, Jonathan M Davis 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.
>
> - Jonathan M Davis
>
This is not really problematic. Note that the /only/ improvement in the
DIP that does not apply to library tuples is the tuple construction syntax.
More information about the Digitalmars-d
mailing list