One thing I’ve become accustomed to over the years is that there are a lot of C++ haters. They have their reasons – some good, some bad – but they are never afraid of sharing their opinions. An article on Slashdot this week touting the release of the C++11 standard should have been a hotbed of language trash talk – instead, it was kind of a low key discussion of both the new language features and some retrospection about the language itself. Where have the haters gone?

The Epitome of C++ Hate

There really is no better example of C++ hate than the screed arising from the poison keyboard of Linus Torvalds back in 2007. One paragraph sums it up well:

C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it, to the point where it’s much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.

Linus asserts that C++ is actually sort of a honey-trap, pulling in the substandard programmers and keeping them out of decent C development.

Reading through the most coherent parts of his rant, it is my opinion that much of his ire is directed against a couple of real problems:

  • The early adopter’s fondness for Object Oriented Programming (OOP), which leads to objects everywhere – and particularly in places where they aren’t needed.
  • The more sophisticated user’s fondness for advanced library and language features found in places like boost.

    My personal observations are obviously very subjective, but I feel like the excesses of OOP peaked back in the early part of the last decade. It’s been a while since I saw a program were a user did integer math using a type called Integer derived from something called Object.

    These days I see OOP being heavily used for large libraries, and used internally in projects where it makes sense. Often “making sense” is as simple as using objects for RAII, which is really not OOP, just good resource management. Things like RAII are really just better C – providing some guarantees on resource usage that can’t be made when programming in straight C.

    And best of all, the boost language features that Linus didn’t like in 2007 made their way into TR1, and finally into C++11. No longer will you need to worry about rebuilding boost for your compiler every time there is a new release of either product. From this point on, it should just work.

    The Slashdot Crowd

    So instead of seeing a bunch of comments in the vein of Linus’s, the recent Slashdot article contained virtually no blanket dismissals of C++ as something a sane programmer would use. The negative comments were much more constrained, maybe aimed at a pet peeve instead of the language as a whole:

    printf() isn’t typesafe, but it’s a fuckton more readable than all that cout formatting stuff. Also, the fact that it’s not typesafe isn’t really an issue if you don’t suck – trivial unit testing will pretty much show any problems immediately. Besides, gcc/g++ is nice enough to warn you about egregious ones now.

    I don’t think you’ll see a lot of people flaming C++, there just aren’t that many people that care one way or the other anymore.

    I think some of the new features look nice but mainstream use has been shifting away from C++ for a while and I’m not sure I see these new features drawing many back…

    Are the features useful? Yes, but they’re taking a complex language and slapping on yet more functionality. Some new C++ code syntax doesn’t even *look* like C++ anymore it’s so different. Not everyone is a C++ guru and the language is bad enough supporting so many different paths to the same implementation outcomes. This is just going to make staffing, testing, training, and code review that much worse trying to juggle yet another barrel-full of C++ “improvements”.

    Why the Dropoff?

    I think there are two reasons for the drop in C++ antagonism.

    The first is the increasing diversity of languages in use today. Over the past 10 years, the most popular programming languages like Java, C, C++, and VB have all experienced drops in adoption. In 2002, the top four languages might have claimed almost 70% of the Tiobe Language Index. Today the top four represent less than 50%. Language selection has been democratized as the bottom tier of the top 10 gains representation in large markets where it makes sense.

    In other words, it was a lot easier to focus your wrath on C++ when it represented 20% of the projects out there instead of the 8% of today.

    The second is inevitable rationalization of the earlier adopters. C++ programmers in 1998 saw objects behind every tree. In 2003 they were building insanely complicated template metaprogramming frameworks.

    All this crazy stuff settles down over the course of a few years as the C++ mainstream settles into paradigms for things that actually work sensibly. Templates for container classes? Sure. Templates for mathematical computation? Uh, no thanks.

    Final Analysis

    There is a lot of nice stuff in C++11, and nothing that is going to take years to figure out. A lot of it will lead to more readable code, and that’s always good.

    The pace of change is pretty comfortable for me. These language features will be rolling out over the next few years, and as they drop into our favorite compilers, we will pick them up quickly.

    I, for one, welcome our new ISO overlords.