Jorgen Grahn said:
([C++] is also extremely complex; most people seem to agree about
that.
I won't do C++ advocacy here, except I'll note that I don't find it
particularly complex (and I'm not particularly smart). Working with
it is like working in C, except you don't have to invent linked lists
over and over again.
So why hasn't C disappeared then, as everyone rushes to use C++ which is so
much better?
A good question, and I often ask myself that.
C works, that's one reason. It's known not to be a toy language!
Another may be a certain conservatism in the ecosystem where C is
strong (Unix, embedded -- the areas where I myself work). In the
Microsoft or Java worlds people seem prepared to switch everything and
relearn once a year. I think it takes years to be optimally
productive in a programming environment, so I assume those people are
always working /below/ their optimal level.
A third is I think organizations got burned in the 1990s when they
tried to switch from C to a not fully mature C++, and at the same time
focus heavily on OOA/OOD/OOP and navel-gazing in general. I know
examples of companies which had disaster projects back then, and then
blamed and more or less banned C++ until now.
Fourth: there are many more ways to do things in C++, and it's hard to
get people to agree on one. I sometimes think this is the best
argument for C -- although there are surprisingly many incompatible
ways to treat C too!
(BTW you only have to invent linked lists once. You might have to implement
them more than once, but since my data structures were linked to each other
in up to seven different ways, a simple generic off-the-shelf linked-list
type in a library wouldn't have worked.)
I've tried to get into it every so often, to discover the mysteries of OOP
and templates and generics and polymorphism and so on.
I never could get my head around OOP and polymorphism either -- write
your code as a deep class hierarchy and I'm immediately lost. I
suspect it's a personality thing, because experienced programmers tell
me it's the way to go, at least for some kinds of problems.
Fortunately you don't have to do it: you can design all your classes
without any inheritance. The C++ standard library itself rarly uses it.
The big benefits of C++ lie elsewhere, and would IMO feel more natural
to someone coming from C.
But when I looked at
examples, it was stuff I'd already been doing for years anyway in some
dynamic language or other, without even knowing I was doing it! And with a
lot less effort. C++ might just do some things a bit faster.
In recent years I've begun to rewrite much of my Python code into C++.
Not because of speed usually -- I noticed the lack of static type
checking made my code hard to maintain ... I like Python, but the
"rigidness" of C and C++ suits me better in the long run.
(In my case I use two levels of language: a higher level (than C++) dynamic
language to do most of my work, and a lower-level one (C or like C) to
implement the other; this one doesn't need to be fancy. I don't need a
generic, flex array type, because that's in the other language.)
That's not the scenario I was thinking of ... True, if you're program
is e.g. Python with some "leaf" parts in C, you have little use for C++.
/Jorgen