
Why do C++ folks make things so complicated? - prog
http://www.johndcook.com/blog/2011/06/14/why-do-c-folks-make-things-so-complicated/
======
danieldk
If you want to make such a distinction, Qt is probably what would come close
to top-C++. It offers dynamic binding via signals/slots, Java-like iterators,
simple multi-threading/parallelization, signal/slot-driven networking,
database access, and some automatic memory management (deletion via parent
widgets, and auto-pointers). It only misses the proposed compiler warnings to
indicate that 'bottom-C++' is used.

Still, for the average programmar 'top-C++' makes a miserable language. Want
to write a simple class? You have to make a separate header file and decide
what methods to inline/make virtual, etc. Want (binary) compatibility? You'll
have to worry about things such as PIMPL and d-pointers.

It's a low-level language, and low-level issues will always leak into higher-
level subsets. And why should one go through the effort? The old mantra "write
in a higher language, rewrite what is too slow in C/C++" works fine.

~~~
blub
Performance is a cross-cutting concern, you should factor it into the design
of the application and not remember it when doing field tests and noticing
that the software is too slow.

This doesn't mean that you must use C or C++, but assuming that you can always
rewrite the slow parts in C or C++ is inviting disaster.

~~~
jpablo
Doesn't that go against all we have learned in CS? Early optimization being
the root of all evil. And don't optimize what you think will be slow, but what
you have measured to be slow?

~~~
groby_b
If we had learned something, we'd have learned the FULL quote, wouldn't we?

"We should forget about small efficiencies, say about 97% of the time:
premature optimization is the root of all evil"

Note, "small" and "97%".

That means that you should make the right large-scale decisions _before_ you
code. Or measure.

~~~
jasonwocky
Yes. Another way to put this is that there's a difference between "designing
to be sufficiently performant" and "optimization".

~~~
groby_b
It also means "don't be boneheaded about local performance". That's the other
3%. I wish it didn't need to be said, but there are quite a few projects I've
seen where people blatantly ruined performance, all the while quoting Knuth.

------
cageface
C++ already contains "top" and "bottom" C++. You can write boost-style code,
with heavy use of smart_ptr and STL algorithms & functors, or you can stay
pretty close to the "C with classes" layer.

~~~
16s
That's the thing I like most about C++. I can do any type of programming in it
(OOP, functional, procedural, templates, etc.). I can roll my own data
structures or use the built-in STL containers while working with low-level
C-like code. I'm not sure why so many people complain about it. Once I began
using it, it quickly became my primary programing tool on Unix, Windows and
Macs.

~~~
derleth
"Beware the Turing Tarpit, where everything is possible but nothing of
interest is easy." -- Alan Perlis

C++ is, for many people, a Turing Tarpit: Ask yourself why you wouldn't write
something in assembly, and that's why they wouldn't write it in C++.

In specific, C++ doesn't have built-in support for real garbage collection.
This means a lot of the idioms I take for granted in languages like Common
Lisp and Haskell, to pick two very different languages that have true gc in
common, are effectively impossible in C++.

For example, I can't reliably pass complex data structures around using
function composition (think f(g(h(x)))) because I can't rely on them
_existing_ from one function call to the next; an allocation may have failed
somewhere up the line and now what? Adding in all the code needed to handle
that isn't just a pain, it obscures the algorithm to the point I'm not
programming the same way anymore. I'm not even _thinking_ the same way
anymore.

Now for a purely personal anecdote: I quite like C. I can do certain things in
C about as fast as I can think of them (mostly, things involving the POSIX API
and no really complex data structures). I occasionally get the notion to add
some C++ to my bag of tricks; not C-With-Classes, but C++ with Boost and the
STL and whatever else g++ can handle these days. I might as well learn to swim
by jumping in 500 feet upstream of Niagara Falls; there's "hitting the ground
running", there's "hitting the ground doing back-flips and double-
somersaults", and then there's "hitting the ground juggling sharpened sabres
and gently convincing hungry wolves to not eviscerate you." Honestly, it
wasn't this hard to learn how to write macros in Common Lisp. I don't know if
the problem is just me or if it really is that bizarre in C++-land.

~~~
cageface
C++ is the wrong choice for many applications, and I'll reach for a higher-
level language if I can, but if you need the low-level control of C and need
_some_ tools for better abstraction C++ is your only real option.

------
mrich
C# comes to mind when he is talking about top/bottom C++. They got this right,
plus added some neat high-level features.

~~~
JoachimSchipper
Actually, the commenters are arguing about what languages are best used in
those roles; e.g. C as "bottom C++", Python as "top C++" - or, indeed, C# as
"Top C++".

C# is nice, but I wouldn't want to write a kernel in it.

~~~
profquail
_C# is nice, but I wouldn't want to write a kernel in it._

Why not? :)

<http://singularity.codeplex.com/>

When C# is combined with Code Contracts / static verification, you get fairly
clean/performant code and strong safety guarantees. I think that'd be quite
nice for kernel programming.

------
michaelfeathers
I think that the main reason that C++ is so complicated is because they've had
to maintain compatibility with C's model. The declaration/definition and
value/reference dichotomies double up a lot of work. When you add the fact
that they wanted to base STL on pointeresque semantics (iterators) and people
started using template meta-programming to deal with the lack of reflection,
well, it all got complicated.

------
dedward
Simply a combination of it's nature - it's C++, and It's been around a long
time. It's easy to make messy stuff with it.

