On Friday, 26 October 2012 at 22:43:44 UTC, H. S. Teoh wrote:
I'm getting a bit frustrated with the Phobos bugs related to
ranges and
std.algorithm. I think we need to increase the number of
unittests. And
by that I mean, GREATLY increase the number of unittests. Most
of the
current tests are merely sanity tests for the most common usage
patterns, most basic types, or tests added as a result of fixed
bugs.
This is inadequate.
Unit tests are not the solution to this. There are too many range
combinations and types to effectively unit test everything. What
we need is proper semantic support for ranges (and other
conceptual classes of types). For example, this should not
compile:
void foo(Range)(Range r) if (isForwardRange!Range)
{
r.popBack();
}
But it will, because of the way templates work in D -- nothing is
checked until you try to use it.
Imagine I could compile non-template code like this:
void foo(int x)
{
writeln(x.name);
}
Imagine you had to try to call it before the static type error
was caught. This is not a way to write robust code, especially
with the combinatorial explosion of range types that exist.
Template constraints are nice, but not enough. We really need
something *like* the proposed C++ concepts, or just something
analogous to interfaces. I should be able to write something like
this:
void foo(ForwardRange Range)(Range r)
{
r.popBack();
}
And *immediately* get a type error without having to instantiate
it with a variety of different range types. This is the only way
I can see these kinds of problems going away. Unit testing does
not scale with exponential use cases.