Re: C++ is complicated
On 21 Mar., 18:09, jacob navia <ja...@nospam.org> wrote:
peter koch wrote:
For several reasons, one being that inheritance does not solve the
problem. But even if it did, you would require an inheritance relation-
ship that would quickly be unmaintainable. Just imagine all those
properties you would have to define in order to even simple types: are
they default-constructible,
yes
assignable,
yes
copy-constructible,
yes
can you compare them,
yes
do they have a "less-than" relationship
yes
a.s.o.
Well, primitive types (int, double,char,short,long,
double, float,long double,long long) are all numbers.
If you exclude strings and arrays, they have all the above
properties. Those properties do not have to be specified,
since they are intrinisc to the language!
Using concepts, all old code would have to be thrown out if inheritance or
something like that were to be used instead.
Why?
Because e.g. int is a primitive type, that does not inherit from these
concepts. Therefore, I would not be able to use my new concept-based
container with integers. What is worse, I would not be able to rewrite
the standard library so that it could take advantage of concepts.
Remember: one advantage of concepts is that they should simplify
programming for the users of the libraries. Not having concepts in
std::vector probably would not be acceptable.
If I needed some "concept" I would create an abstract class
that has all those properties and the compiler could check
that the given type conforms to all the properties of the
specified class.
The only reason that this is not done is that OO is no longer
"in", i.e. the OO "FAD" has disappeared. We have new fads
now.
OO is not the silver bullit, and it never was considered so - at least
by the C++ community.
C++ always was a multi-paradigm language and will continue to be so.
It will be left to the maintenance programmer to figure out
then, why the mixture of old+new fads doesn't work.
Old code will continue to work - what are you getting at? And just as
important: you can use existing code in new concepts-based code,
something that would not be possible with your proposal to abuse
inheritance.
/Peter