The Null Device

Edward C++hands

Edward C++hands, or an essay by Bartosz Milewski on why C++ is harmful to progress:
I’ve been looking for a good analogy of what programming in C++ feels like and I remembered this 1990 Tim Burton movie, Edward Scissorhands.
Having scissors for hands in not all that bad. Edward has many talents: he can, for instance, create stunning dog hairdos.
I often have these kinds of thoughts after attending C++ conferences: this time it was Going Native 2013. The previous year, the excitement was all about the shiny new C++11 Standard. This year it was more of a reality check. Don’t get me wrong — there were many stunning dog hairdos on display (I mean C++ code that was elegant and simple) but the bulk of the conference was about how to avoid mutilation and how to deliver first aid in case of accidental amputation.
The gist of the article is that, because of backward compatibility requirements with C (also known as “high-level assembly language”), C++ is a deathtrap, with numerous potential pitfalls and even more schemes to mitigate them, each with its own flaws and shortcomings:
The C++ lore is that you should avoid naked pointers, avoid arrays, avoid delete. So the remedy for the lameness of malloc is operator new, which is also broken because it returns a dangerous pointer and pointers are bad. We all know (and have scars on our faces to prove it) that you should use the Standard Library containers and smart pointers whenever possible. Oh, and use value semantics for passing things around. No wait! Value semantics comes with a performance penalty because of excessive copying. So what about shared_ptr and vectors of shared_ptr? But that adds the overhead of reference counting! No, here’s a new idea: move semantics and rvalue references.
Milewski's solution is to move to a functional language like Haskell, or if you can't, write your C++ code as if it were in Haskell:
Of course, you might recognize all these pro-concurrency and parallelism features as functional programming — immutability and pure functions in particular. At the risk of sounding repetitive: Haskell is way ahead of the curve with respect to parallelism, including GPU programming. That was the reason I so easily converted to Haskell after years of evangelizing good programming practices in C++. Every programmer who’s serious about concurrency and parallelism should learn enough Haskell to understand how it deals with it. There is an excellent book by Simon Marlow, Parallel and Concurrent Programming in Haskell. After you read it, you will either start using functional techniques in your C++ programming, or realize what an impedance mismatch there is between parallel programming and an imperative language, and you will switch to Haskell.

There are 1 comments on "Edward C++hands":

Posted by: unixdj Sat Sep 21 15:30:27 2013

The problem of C++ design is not only the absurd desire to grow a glorified PDP assembly language into an object oriented system, but also the practice of adding badly designed and badly fitting features into an already overblown language. Even in the primitive-by-today's-standards version of twenty years ago the overhead of added complexity was too big to be worth the effort of dealing with for the little benefit it was giving the programmer, compared to C. And it's hard for me to understand people who disagree with this assessment. So was it for Rob Pike, but he's a smart guy, so he figured it out:

And, of course, there's the (pre-C++11) C++ FQA Lite and its short summary:

Want to say something? Do so here.

Post pseudonymously

Display name:
To prove that you are not a bot, please enter the text in the image into the field below it.

Your Comment:

Please keep comments on topic and to the point. Inappropriate comments may be deleted.

Note that markup is stripped from comments; URLs will be automatically converted into links.