C++ guys hate static_if?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 14 10:48:27 PDT 2013


On Thu, Mar 14, 2013 at 12:48:28PM -0400, Andrei Alexandrescu wrote:
> On 3/14/13 11:50 AM, deadalnix wrote:
> >On Thursday, 14 March 2013 at 15:38:53 UTC, Andrei Alexandrescu wrote:
> >>On 3/14/13 11:05 AM, monarch_dodra wrote:
> >>>Having to instantiate a template just to check to make sure it is
> >>>semantically correct is a huge pain.
> >>
> >>I'm not sure about that. The way I see it, no code should be not
> >>delivered without being unittested. Ubiquitous unittesting is now
> >>mainstream. The way I see it, a type system on top of templates
> >>would only help people who don't write unittests.
[...]
> >I don't say that unittest are useless, but why rely on unittest when
> >the machine can do the job for you ?
> 
> In both cases the machine does the work. My argument is that adding an
> additional layer of typing on top of templates caters to people who
> want to ship code that has literally zero testing. That's not a
> priority as far as I'm concerned.
[...]

I don't agree. Phobos is a prime example. Does Phobos have unittests?
Yes, and lots of them. Does it still have non-compilable template
instantiations? Yes, because unittests can't cover all possibilities --
there are too many possible combinations of template arguments. There
are bound to be untested combinations which don't work but we're unaware
of.

We could, of course, automatically generate a very large number of
template argument combinations and check to see if they're instantiable.
In fact, we could write unittests that loop over every combination of a
given list of types and instantiate the template to be tested with them.
This is well within D's metaprogramming capabilities.

But if we have to go that far, then it begs the original question: why
not have the compiler do that for us? The compiler is better poised to
make certain deductions using the type system, semantic analysis, etc.,
so that it doesn't literally have to enumerate every possible
combination of template instantiation arguments just to prove it has no
uncompilable instantiations.

While I don't think D in its current state is going to be able to do
this in a full way, the argument of catering to people shipping code
without testing is invalid IMO.


T

-- 
Life would be easier if I had the source code. -- YHL


More information about the Digitalmars-d mailing list