More complexity creep in Phobos
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Mar 28 04:20:55 UTC 2019
On 3/27/19 11:22 PM, Meta wrote:
> It seems like if you see some weird code in Phobos but you don't
> understand why it was written that way, there are 3 main reasons that
> account for 99% of these cases:
>
> - string (autodecoding)
> - alias this
> - enums
"Mistakes made by people" is missing from that list. Which include mine
of course.
There's this nice notion of reasoning by first principles vs. reasoning
by analogy:
https://fs.blog/2018/04/first-principles/
A very nice essay - recommended outside this discussion's context, too.
The levenshteinDistance issue is a direct application of the two kinds
of reasoning. This is reasoning by analogy:
"DirEntry converts to string and is used by some people as such. They
pass it to functions, and some accept it but some don't. It follows by
analogy that the Levenshtein distance algorithm should be worked out to
accept it, too."
In contrast, the reasoning from first principles should powerfully
override that:
"Levenshtein distance operates on forward ranges. All that stuff that
changes the signature of levenshteinDistance to accept other artifacts
is nonsense. Whoever wants to use it should carry the conversion to
forward range themselves."
It follows that the correct answer to this generalization frenzy should
be: "We work with ranges and character types. If you've got enums and
alias this and whatnot, more power to you but to use the standard
library you must convert those to the stuff we support."
More information about the Digitalmars-d
mailing list