3 ms·
Thanks for your kind words. In D's standard library we consistently attempt to define each and every algorithm in its most general form, with opportunistic spec
by andralex 15y ago
Thanks for your kind words. In D's standard library we consistently attempt to define each and every algorithm in its most general form, with opportunistic specializations wherever available. As a trivial example, startsWith works on average faster on sequences with O(1) length because it can compare the lengths beforehand. D's generic amenities (static if and constrained generics in particular) make it very easy to write code with lots of such micro-specializations effortlessly. You just say "oh, do these guys support the length method? Then if lhs.length < rhs.length return false".
We've managed to reach a very high leverage in std.algorithm (http://d-programming-language.org/phobos/std_algorithm.html http://d-programming-language.org/phobos/std_algorithm.html) because of that, and there's seldom a need to redo by hand one of its algorithms for efficiency or convenience reasons.