C++ guys hate static_if?
Dmitry Olshansky
dmitry.olsh at gmail.com
Thu Mar 14 10:20:11 PDT 2013
14-Mar-2013 21:07, Andrei Alexandrescu пишет:
> On 3/14/13 12:54 PM, deadalnix wrote:
[snip]
>>> Q: So if static typing is insufficient, why not rely on unittests
>>> alone to do all checking? It's also bothersome for some people to obey
>>> types, annotate stuff etc.
>>>
>>> A: There are still errors that can be better detected with static
>>> checking, and many dynamic programs that work by accident etc.
>>>
>>
>> I see we agree this is the same problem materialized in another form. I
>> find it rather weird that you conclude different things when the problem
>> is the same in the first place.
>
> Very simple. Traditionally there's two crucial epochs known as
> compilation time and run time. (There's some minor distinctions like
> link time etc.) The whole notion of concepts and other type systems for
> templates is predicated on three crucial epochs: library compilation
> time, library user compilation time, and run time. The logic goes,
> someone writes a generic library and wants to distribute it to users.
> Users shouldn't ever see bugs caused by e.g. typos in the library.
>
> So the crowd that use meta-type systems is formed of library writers who
> want to distribute libraries without ever instantiating them. I don't
> think that's a good crowd to cater for.
>
> I've been surprised to figure how many people don't get this flow, or
> only have a vague image of it. Although meta-types are arguably "the
> right thing" to do, they're a lot less attractive once it's clear what
> scenarios they help.
>
Maybe we then should help people that routinely instantiate their
templates to see if they compile. Say add a library artifact tryInstantiate:
auto foo(...)(...);
static assert(tryInstantiate!(foo, TypesForFirstArg!(...),
TypesForSecond!(foo, ...),...);
Inspired by the ubiquitously common foreach(type; TypeTuple!(A,B,C)){
...} unit test pattern.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list