DIP54 : revamp of Phobos tuple types

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Dec 23 03:08:14 PST 2013


On 12/23/13, Dicebot <public at dicebot.lv> wrote:
> http://wiki.dlang.org/DIP54

Quoting:

----
There is also a private `std.typetuple.Pack` which is similar to
current `std.typetuple.Tuple` but does not auto-expand. It is a tool
absolutely necessary for more complex algorithms used in
metaprogramming >>and is frequently re-invented in user libraries /
projects<<.
----

If you simply remove the auto-expanding TypeTuple you will force
coders to reinvent it. This may not seem like a big deal since you can
simply do "alias List(T..) = T;", but it's a convenience template that
should stay in Phobos.

Think of it like the range primitives of arrays that are implemented
in std.array. I would hate to have to re-implement
empty/front/popFront/etc for arrays every time I used them if they
suddenly went missing in Phobos, even if they're very trivial to
implement. Especially when all of my code already depends on those
functions being there.

If we keep an auto-expanding TypeTuple template (but perhaps rename
it), then all the user has to do to keep his code working is to do a
global search & replace (transition is simple). It does still break
code however.

But if you remove it entirely, the user has to add his own TypeTuple
template in another module, and then he has to add new import
declarations in every module that used TypeTuples. That's even worse
than renaming.

---

Personally, I think the proper approach is:

1. Keep TypeTuple, but perhaps schedule it for renaming.
2. Introduce non-expanding equivalent to TypeTuple (in other words:
make Pack public, but maybe with a different name though).
3. Add a set of documentation clearly explaining the difference
between the various tuple types in Phobos and the languaage.

It seems to me that it's really the #3 that is the root cause of
confusion, as #2 is an additive change that doesn't break any code but
introduces something people were reinventing in their own libraries.

The real cause of people wanting #1 is #3, the lack of proper
documentation. I have not had any problems understanding what the
TypeTuple template means and how it relates to Tuple as soon as I
started using both more frequently. If we have proper docs, we could
even link to it from the documentation of all the tuple types in
Phobos.

If we fix #2 and #3 I believe we'll have an improved situation and
happy **current** users, as no code will break. Maybe absolute newbies
will take a while to learn the difference between these various
templates, but that's what tutorials/documentation is supposed to help
with.

---

We always seem to forget that all newbies will eventually become
experienced current users. Current (experienced) users need a little
respect as well, not everything has to be tailored to the next batch
of newbies by breaking existing users' code. Documentation and
tutorials are the solutions here.

I vote against this DIP.


More information about the Digitalmars-d mailing list