C++ guys hate static_if?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 14 10:17:37 PDT 2013


On 3/14/13 1:07 PM, bearophile wrote:
> Andrei Alexandrescu:
>
>>> This is usualy much better to have the compiler smash your mistake right
>>> into your face than discovering with a unittest much latter.
>>
>> I don't think so.
>
> Why?

It's just an entirely different scenario. I can easily imagine a 
unittest failing to cover the entirety of possible flows in a function 
(particularly when exceptions get involved!). So clearly unittests 
define a spectrum of checking.

In contrast, with typos in templates unittests are Boolean function. 
Either the thing compiles or it doesn't, no other way about it.

Consider https://github.com/D-Programming-Language/phobos/pull/1205. I 
wrote unittests for the straight version and for pairwise summation, but 
not for Kahan. The code passed unittests, but clearly that wasn't 
enough. So I added the SList-based test to make sure the Kahan version 
works, and lo and behold I found typos in it that made it uncompilable, 
AND then run-time bugs that made it produce incorrect results. A concept 
system would have helped me there if my intent was to ship Kahan 
summation without ever testing it. That's not an intent we want to cater 
for!

>> 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.
>
> If those people want yo write zero unit tests, they will write zero unit
> tests in both cases. I have seen D code like that. Introducing some
> compiler tests isn't going to make that situation worse and it's able to
> give better&nicer error messages when you have just written a template
> and you have not yet written a unittest (assuming you aren't using
> Test-Driven-Development).

It has happened (very rarely) that pieces of generic code in Phobos had 
errors. I don't think those deserve help from the compiler.


Andrei


More information about the Digitalmars-d mailing list