From: John Max Skaller (skaller_at_[hidden])
Date: 2001-08-15 18:56:31
Aleksey Gurtovoy wrote:
> John Max Skaller wrote:
> > Now, I HATE traits libraries, (template equivalent
> > of global data .. )
> "Traits" class templates in type_traits library are not in any way an
> equivalent of global data; they are compile-time "functions" than operate on
> types; so there is no reason for hate :).
Yes there is: these 'functions' generally consist of
a large set of specialisations, and they fail to work
immediately you supply an argument for which there is no
specialisation, so you have to 'augment' the function
with a suitable specialisation. Such specialisations
are effectively global data: the template is in NO WAY
generic, it is in fact a huge switch over global case data.
An example is the trait which tells you which character
of a type is the '\0' equivalent.
This is really bad style. To add a new type T which
is to act like a character, you have to modify a completely
unrelated template with a specialisation: you're actually
extending something in the sacred 'std' namespace.
Contrast this fragile lunacy with the module system
used in SML and you'll see why I hate traits so much:
traits are the enemy of modular design -- you're forced to
scatter your 'module' all over the place to make it work.
Again, implicit coupling.
As an example of what can go wrong:
I make a type UNICODE which is kind of cute. But i don't
play the traits game. So you can't use it with basic_string/
stream io, you need the trait for 'null char' defined for that.
So you go and add the specialisation.
Woops. Joe, Fred, Samantha, and Alex all had the same
idea; the ODR is broken if you try to combine your code.
[My argument doesn't apply to genuinely polymorphic
templates used as 'type functions', that is, ones which
are parametrically polymorphic. But the ones with lots
of specialisations are just a huge hack for the lack
of a proper concept of unification, both at the
executable and tempate level]
-- John (Max) Skaller, mailto:skaller_at_[hidden] 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 New generation programming language Felix http://felix.sourceforge.net Literate Programming tool Interscript http://Interscript.sourceforge.net