Tuple literal syntax
retard
re at tard.com.invalid
Thu Oct 7 03:39:01 PDT 2010
Thu, 07 Oct 2010 03:20:23 -0500, Andrei Alexandrescu wrote:
> Sorry for being Debbie Downer in this thread, but I'm not seeing a lot
> of progress here. This is nothing but a syntax cutesy that helps
> Tuple!(A, B) and tuple(a, b) and leaves all other issues related to
> tuples unresolved (I'm actually afraid that it exacerbates them).
>
> One good thing about Tuple is that it allows names of fields, so
> functions can return tuples with conveniently named fields, e.g.
> Tuple!(bool, "found", size_t, "position") etc. without having to define
> little structs everywhere and fostering simple, clear code on the caller
> side.
Why do tuple fields need a name? Isn't this a new ad-hoc way to introduce
structural typing in D? I often start with tuples, but if it turns out
that the value is used in many places, it will be eventually replaced
with a struct (e.g. coordinates in a gui / gamedev) for better type
safety. Even with structs the need for field names is very rare. The real
need for tuples is in very special cases where the syntax needs to be
light.
More information about the Digitalmars-d
mailing list