finding errors with templates without instantiating them
bearophile
bearophileHUGS at lycos.com
Thu Sep 12 09:53:05 PDT 2013
Tudor Andrei Cristian Alexandrescu:
> I'm not against it, but I find it a very small improvement. Its
> user base is exactly people who want to write and deploy a
> template without ever testing it at all, ever. I have a hard
> time catering to that hypothetical crowd.
This is an interesting discussion topic.
Mistakes and bugs are mechanically caught at several different
moments, sometimes even before compile-time, thanks to squiggly
red lines shown by the IDEs where there's a syntax error. Then
bugs are found during compilations, by contracts and unittests at
run-time, etc.
If you have a significant amount of template code already
written, with unittests, etc, then the small amount of bugs
spotted by this enhancement request is not much significant,
because at that stage of the development of the code you are
supposed to catch the remaining bugs using a high coverage ratio
of unittests, etc. So in this case I agree with you this feature
is not much useful, or it could even be harmful if programmers
trust it too much.
But there is a another situation, when you don't have much new
code written. You have just written 5-15 lines of templated code,
and you have not yet written unittests on it (I write lot of
unittests, but usually after writing the code), at this early
stage I think it's useful to have a D compiler that performs
simple analysis of the template code, to catch the simple
mistakes very quickly. This helps me focus on the less obvious
errors, and then I can write the unittests to catch the semantic
mistakes of the code.
So I think this feature is not useful the seasoned code you seem
to refer to; it's useful to catch as soon as possible silly
mistakes inside just written templated code, that allows the
programmer to focus on the less obvious bugs and on writing the
unittests with high coverage.
Bye,
bearophile
More information about the Digitalmars-d
mailing list