What's the deal with the massive duplication in std.meta?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Apr 30 22:03:41 UTC 2021
cc Walter, Atila
Phobos is like a toddler: you turn away for a few moments, and then back
and something really odd has happened.
The massive duplication of declarations in Phobos is definitely
unacceptable. That is, literally unacceptable - the pull requests
introducing it should not have been accepted, and the issue should have
been elevated as a major language issue.
I protested this before and the matter has been discussed maybe about
two years ago but nothing has been done about it.
It all starts simple, like a toddler babble:
```D
alias Alias(alias a) = a;
alias Alias(T) = T;
```
The reader (including seasoned maintainer) would go like, "What? Why
does it need to be defined twice? Wouldn't a type also fit an alias?"
And indeed if said maintainer comments out the second declaration, a
couple of obscure errors show up in unittesting (mind you, not
unittesting of std.meta, but of completely unrelated modules).
Bah. Passons. Let's read further down (and skip the weird OldAlias
thing, well it has package protection so it qualifies as dirty laundry),
where more harbingers of bad news show up:
```D
template staticIndexOf(T, TList...)
{
enum staticIndexOf = genericIndexOf!(T, TList);
}
template staticIndexOf(alias T, TList...)
{
enum staticIndexOf = genericIndexOf!(T, TList);
}
```
At this point clearly there's a huge red flag waving because this is a
public symbol, and if this duplication pop up at top level, it's a sign
that many other public symbols will suffer the same fate. (Spoilers:
they do. They all do.)
This kind of code is clearly, absolutely, pound-on-the-table,
end-of-discussion not acceptable at scale. If bad code has smell, this
is a rotten beached blue whale carcass.
This code should have NEVER been accepted upon review. Instead, the
reviewers should have filed a TOP PRIORITY bug report to dmd "Not
binding types to alias templates forces unscalable code duplication for
all typelist primitives".
This needs to be fixed, and very urgently.
More information about the Digitalmars-d
mailing list