Why people think C++ is Complicated

Why would someone be using C++ in the first place? 

Article By: John D. Cook

Most likely because they need performance or fine-grained control that they cannot get somewhere else. A Ruby programmer, for example, can make a design decision that makes code 10% slower but much easier to use. “Hey, if you want the best performance possible, why are you using Ruby? Didn’t you come here because you wanted convenience?” But the C++ programmer can’t say that. It’s not turtles all the way down. Often C++ is the last human-generated language in a technology stack before you hit metal.

From The Register

Apple’s Mac OS X, Adobe Illustrator, Facebook, Google’s Chrome browser, the Apache MapReduce clustered data-processing architecture, Microsoft Windows 7 and Internet Explorer, Firefox, and MySQL — to name just a handful — are written in part or in their entirety with C++.

Certainly there is a lot of software implemented in higher-level languages, but those high-level languages are almost always implemented in C or C++. When there’s no lower-level language to appeal to, you have to offer a lot of options, even if 90% of users won’t need those options.

But, that doesn’t mean all C++ libraries have to be complicated. The argument above says that the lowest layers have to be complicated and they’re written in C++.  But why couldn’t the next layer up also be written in C++?
Some time in the 90’s I ran across an article called “Top C++.” I’ve tried unsuccessfully since then to find a copy of  it. As I recall, the article proposed dividing C++ conceptually into two languages: Top C++ and Bottom C++. Explicit memory management, for example, would be in Bottom C++. Top C++ would be a higher-level language. You could, for example, tell a compiler that you intend to write Top C++ and it could warn you if you use features designated as Bottom C++.
Of course you could slip from Top C++ into Bottom C++ if you really needed to, and that’s the beauty of using one language for high-level and low-level code. Application code in C++ would use Top C++ features by default, but could deliberately drop down a level when necessary. A section of Bottom C++ could be marked with comments or compiler pragmas and justified in a code review. Instead of having to cross a language barrier, you simply cross a convention barrier.
I thought this was a great idea. I’ve followed this approach throughout my career, writing high-level C++ on top of low-level C++ libraries. To some extent I put on my Bottom C++ hat when I’m writing library code and my Top C++ hat when I’m writing applications.
But most of the world has decided that’s not the way to go. If you’re writing C++, it might as well be Bottom C++. Instead of Top C++, write VB or some other higher-level language. There’s very little interest in high-level C++.
I imagine this decision has more to do with management than technology. It’s easier to have people either write C++ or not. If you’re writing C++, then use any language feature any time. I suppose this is a stable equilibrium and that the Top/Bottom C++ partition is not.
Source: John D. Cook

11 thoughts on “Why people think C++ is Complicated”

  1. I wouldn’t say there’s very little interest in top level C++. At my workplace, we use it for almost all of our development (mostly embedded systems, but some GUI stuff for the devices). I love the new functional features added in C++11, especially the anonymous function feature. It is interesting and a little strange to be able to write code like that for some of the higher levels of a project, and then in the same language implement a device driver.

    I think this sort of thing is the reason why C++ is both considered so difficult to learn, and why it is so widespread. It pretty much allows anyone, no matter what their style/preferences/needs are, to write code in that style. But you aren’t forced to use any particular style (Well, doing a purely functional approach would be horrific, but again, not impossible).
    I think the real key is that you can’t look at a list of included features for C++ and say “Oh, I have to learn all of this”. Just use whatever coding style you like/need, and ignore the features that don’t apply to that style.

    Reply
  2. “… are written in part or in their entirety with C++.”

    Is even a single one of these applications written entirely in C++? Many aren’t even mostly C++!

    Facebook famously uses mostly PHP. Mac OS X is mostly C and Objective-C, with C++ really only used for IOKit. MySQL is a classic C++ success story, but according to Github’s statistics it’s only 49% C++. I’m not sure what you mean by “Apache Reduce”, but if you mean Apache Hadoop MapReduce, that’s 87% Java, with 1.8% C++ only for the C++ language bindings.

    The Register is not exactly a competent technical publication.

    Reply
  3. “Why would someone be using C++ in the first place? Most likely because they need performance or fine-grained control that they cannot get somewhere else.”

    I don’t mean to sound harsh, but you speak like someone who’s never worked on a real programming project (which is strange because I’m sure you have).

    You’re trying to rationalize its success, based on what you perceive is C++’s strength. But it comes across like saying “Why would someone be speaking Hungarian in the first place? Most likely because they need the precision of having 18 grammatical cases that they cannot get somewhere else.” No, the reason most Hungarian speakers speak Hungarian is because they happened to have been born in Hungary.

    Similarly, the most likely reason somebody is using C++ (or any other programming language) is because they’re working on a project that somebody else started in C++. Either it’s their job to work on that program, or they found an open-source program that does 99% of what they need and it’s 100 times easier to add the last 1% than to start from scratch.

    In either case, you don’t pick a language based on what you like best, or is simplest, or fastest, or provides the best abstractions. Network effects completely dwarf all other considerations in the software field.

    What do most of your examples have in common? They’re old programs which survived to the modern age. Flip it around and ask “What was the most popular programming language in the mid-1990’s?” and it’s no surprise that the top 20-year-old programs in 2015 reflect what was hot in the 1990’s. (Nobody is seriously proposing to rewrite all of Microsoft Windows at this point, even if they think C++ is a lousy language.) In 2035 when we look back at the hottest 20-year-old programs, they’ll be written in Ruby and Python and Java.

    Reply
  4. “… are written in part or in their entirety with C++.”

    Is even a single one of these applications written entirely in C++? Many aren’t even mostly C++!

    Facebook famously uses PHP. Mac OS X is mostly C and Objective-C, with C++ really only used for IOKit. MySQL is a classic C++ success story, but according to Github’s stats it’s only 49% C++. I’m not sure what you mean by “Apache Reduce”, but if you mean Apache Hadoop MapReduce, that’s Java, with a little C++ only for the C++ language bindings.

    The Register is not exactly a competent technical publication.

    Reply

Leave a Reply to Anonymous Cancel reply