Skip to content

Why would you learn C++ in 2016?

My reasons to hold on to C++ for years to come.

“C++ is dead”

I’ve been hearing this since I went to the university. That’s like 10 years ago. Back then Java was already dominant language in the corporate world, at least in the USA. If you’re a programmer you’re probably familiar with the Joel Spolsky’s famous rant about JavaSchools (good read as always from Joel). It’s dated Dec 2005. C#, which came around in 2000, was a Microsoft answer to Java and was also said to be C++ killer. Then, the dynamic languages were all the rage. Ruby and Python began trending. Given all those easy-to-use languages, why would you choose  C++ for anything? Isn’t that a prettier C, which again is a prettier assembly language? If you have an hour you can listen to a great talk given by Herb Sutter, and if not, there’s a shorter talk with concrete examples. Take look a TIOBE index and you’ll see that C++ occupies a steady 3rd place in the list of the most popular languages for the past 15+ years. Not bad for an old language. Which brings me to another point…

How do you like them pointers?

Most people who instantly associate C++ with pointers have been taught the wrong way. It’s the old school of “C with classes”. I know from my own experience how bad it is. Exercises with passing multi-dimensional C-arrays to functions. Pointer arithmetics. Manual memory management as if containers and smart pointers didn’t exist. Implementing doubly-linked lists. All that, which should be taught in C classes. Maybe there’s nothing wrong in teaching C++ this way? Well, Think again.

Of course, a professional programmer should understand how pointers work. But that’s not what modern C++ is about. C++ is constantly evolving. What used to be deemed proper code yesterday, can be considered bad style today.

wg21-timeline
source: https://isocpp.org/std/status

The language is getting overhauled. Quoting Bjarne Stroustrup: “C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever”. C++ now has lambdas, memory model, range-based for loops, move semantics, variadic templates and all other less or more advanced things to help you with a task at hand. You have some old code, which needs an update to the new standard? Boom! clang-tidy to the rescue. It’s a super cool tool that uses static analysis to find old patterns in your code and suggest how to alter it. Lack of tools was always a pain when working with C++ but that’s changing. You thought only Java has automatic refactorings? Listen to Chandler Carruth, the LLVM/clang ninja from Google. They apply automatic refactoring to 100 million lines of C++ code at once!

Corporate codebase reality

Lots of CS undergrad folks imagine their careers are going to be sort of a rockstar/ninja/superhero experience. “Just wait ’till the world can see what I can do!”. It has to be this way because, well, “I’m above average“, right? You expect long hours of designing and implementing complex algorithms (at least I did). Then you get your first job and WHAM! You get “schlonged” with 20 years old code that appears to be the result of experimenting with hard drugs. strcpy with fixed buffers scattered over hundreds of files, thousand-line-long functions, 5 versions of hand-written linked lists – you name it. You roll up your sleeves to somehow clean up this mess. “Hold your horses, young apprentice! Business needs this feature implemented yesterday. No, we can’t use new GCC, ’cause the other team’s not ready to switch” – says your manager. Now you think “where did I make a mistake…”.

This problem is not C++-specific. Happy debugging of some old Java code created by a reflection enthusiast. If you’re a web dev you’re likely to be exposed to some radioactive PHP. Even if you code in Ruby or Python or some newer language, the amount of grunt work can suck all the energy from you. “Can you move that button to the right and make it pink?”. That’s the reality of working at most companies. What I’m hitting at is that, barring the swaths of legacy or boring code, there are programming jobs that are both challenging and entertaining with a minimal amount of business BS. Some of those jobs happen to be found in areas where C++ shines…

Where C++ is king: games, HPC, compilers, financials…

If you want to avoid spending your lifetime implementing CRUD stuff, you might consider learning C++ along with choosing a niche. Here are some of my propositions.

Game industry. Almost all AAA titles are created using C++. Video game developer is considered to be one of the most rewarding jobs in a software industry. It’s also one of the most demanding areas of it. Speed is very important, which is why writing effective code is essential. Other than knowing C++ specializing in game dev is mostly about learning theory and patterns that transcend particular API/libraries. Strong graphics and mathematical skills are often required. Enough to learn for a whole career.

HPC. Crunching numbers at extreme speeds requires excellent knowledge of underlying hardware. That knowledge has to be applicable directly in the language. The appearance of GPGPUs along with parallel computation frameworks such as CUDA and OpenCL created demand for C++ programmers with this kind of expertise. If you’re into scientific computing there’s a plenty of jobs out there. Have you heard about machine learning? It’s a hot topic nowadays.

Compilers. This is my favorite area. The LLVM project is such a huge success that it’s hard to find a popular language which either doesn’t have front end written using LLVM libraries or doesn’t use LLVM to generate bytecode. It’s all C++. Although compilers are written in various languages, the theory standing behind implementations is the same in all cases. You get to work with optimizers, static analyzers, debuggers, standard libraries, linkers and all other related tools. There are engineering problems along with theoretical ones.

If you’re into financials, there’re plenty of jobs requiring ability to write low-latency code. Mathematical background is a big plus in this area. Probably most of those jobs involve developing and maintaining high-frequency trading platforms. Also, it’s a great domain if you don’t want to call yourself a programmer. I’d say quants have the most opportunities to get big bonuses among all coders.

That’s just a handful of propositions. What’s common for those niches is that you simply cannot throw large enough number of Java rookies at a problem and expect them to come up with a working, maintainable solution. There’s a lot of domain knowledge required, which you can only get when working with experienced people. That means they are not easily replaceable. Ergo, companies have to pay them more and give them interesting problems to work on in order to keep them. Of course, there’s grunt work to be found everywhere, but it’s much more tolerable when you work on something you genuinely care for.

If you have your own C++ niche or disagree with my line of thinking, please let me know in a comment.

40 Comments

  1. Mike rowe Mike rowe

    Please take the share buttons off the mobile page.

    • kszatan kszatan

      Oops, that’s awful. I’ll take care of it. Thanks for pointing that out.

      • Adam Adam

        That button on mobile…could you move it to the right and turn it pink?

  2. Steve Davis Steve Davis

    Rust

    • kszatan kszatan

      I haven’t yet laid my hands on Rust but I’ve heard good things about it. I wrote this post with the intent to show that C++ is still relevant and alive, and not that it’s the only way to go or the best one. It’s mostly for the people who’ve already invested some years in learning it.

      • Rust is another language based on C++.
        It is good, it is nice, but it is not C++.
        And C++ is improving greatly these years, the last releases are great and what is to come is way better.
        I would encourage anyone to try out Rust, but I would not dare to say that use Rust instead of C++, C++ is still awesome and worth it.
        So, by all means, if anyone hasn’t yet, go ahead and try out C++ 🙂

  3. “Happy debugging of some old Java code created by a reflection enthusiast.”

    …or some new Java code written by a BiFunction/Lambda enthusiast.

  4. Anonymous Anonymous

    The Facebook, Twitter, Google , etc.. buttons on the left side of the page make it very hard to read on aobile phone browser.

  5. Binky Binky

    If someone legitimately can’t understand pointers, they need to stop programming, and not start again, until they’ve learned pointers.

    Not being able to understand pointers underscores a more serious flaw in reasoning about code. Spolsky talks about this on his blog, too.

    • kszatan kszatan

      Maybe you haven’t noticed but I even link to this article in the first paragraph! 😀 I know Joel’s blog and I love his writing.

  6. keripix keripix

    I used to code in C++. But that’s more than 5 years ago.

    Do you have any good resources if I want to relearn C++ again? Especially the new one and the related best practice?

    Thanks in advance.

    • I think that Scott Meyers’ *Effective Modern C++* is very good, especially chapters 3 and 4 (3 is a general overview of a bunch of small changes; 4 talks about smart pointers). For a more general overview that doesn’t get into the nitty-gritty details of all the ways you can get bitten (someone once told me that the summary of every Meyers book is “be afraid–be very afraid”), Stroustrup’s *A Tour of C++* is good, though it doesn’t explicitly call out what’s new and what isn’t. (Full disclaimer: these are the *only* two books on post-2011 C++ that I’ve read. And even after reading them, I still ask bone-headed questions: http://stackoverflow.com/q/28952141/1858225)

    • 22SAS 22SAS

      Just get Scott Meyer’s “Effective Modern C++”, covers the newer C++11 and C++14 stuff with mostly advice on using them well, for an intro cpp-reference and online tutorials are great.

  7. aaron aaron

    pro audio. audio software requires both the capability of controlling low-level timely feeding of audio buffers to device drivers or even directly to register addresses, as well as GUI event-driven functionality. imagine an audio waveform based visual editor or a DAW suite…
    actually: i want to know more!

  8. I don’t think you’re wrong about any of this, especially your point about C++’s widespread adoption in interesting fields. However, my personal opinion is that the language itself, despite the new features in the 2011, 2014, and upcoming 2017 standards, is just not that nice to use; I feel like I understand the language pretty well (which has taken a good deal of time, effort, reading, and experimentation), but I still find that I’m forced to think about piddly details and work around language shortcomings far more often than I’d like*, and even with a large number of warnings (as errors) enabled, I still sometimes finding myself wondering what kind of insane language permits some of the nonsense I find when I’m debugging code. I don’t think this can really be fixed simply by adding more and more features to the language (even though some features, such as modules and concepts, are sorely missed); I think the language is simply too much of a philosophical mixed bag to ever feel coherent in its design (or even its syntax), on top of which the standards committee feels obligated to honor backwards compatibility at almost any price.

    So while I feel that knowing C++ is definitely beneficial for me because it allows me to work on interesting projects, I still hope that better-designed languages will soon have more substantial market share. Dropbox’s recent rewrite of a core part of their functionality in Rust seems like a promising step in this direction. Swift seems like it might be low-level enough to replace C++ in some areas, and despite its origins, it might actually be genuinely viable as a cross-platform language very soon. Elixir might bring the Erlang VM into the spotlight somewhat. And these are just the languages I’m personally interested in; I’m sure there are others that are similarly promising (Nim, maybe?).

    *I’ve given examples elsewhere, e.g. here: http://www.cjdrake.com/why-im-choosing-c.html#comment-2488975899

    • I can’t believe I forgot to mention D. It does seem to be picking up some steam now that Alexandrescu is involved.

    • kszatan kszatan

      While I argue that C++ is not dead and quite the opposite, I also wholeheartedly agree with your comment. Sometimes the language is such a pain in the ass and it takes years just to feel comfortable with it, not to mention how long it takes to really master it. It’s just too big and complicated.
      You’re the second person mentioning Rust in the comments and now I feel I have to seriously get to know it.
      Thanks for your insightful comment.

  9. Totally agree with you. Do what you may, C/C++ are the bread and butter of programming in any domain where performance matters. The domain I work in, EDA is also one good example of the usage of C++.

  10. Moschops Moschops

    “Video game developer is considered to be one of the most rewarding jobs in a software industry. ”

    I disagree. The video game industry reputation is that the jobs are, by and large, badly-paid, over-worked, and in a permanent crunch situation with poor job security. It has a reputation for paying people in perceived glamour rather than actual money, and crunching through naive youngsters who don’t realise how badly they’re being treated.

    • kszatan kszatan

      I wrote “considered” because I’ve heard it countless times from other people that they would like to work in this field. I don’t have first-hand experience with working on video games. It’s sad to hear it looks this way in your area (I assume). However, you can get completely opposite views from people working in any of the fields I mentioned. Good and bad jobs are to be found everywhere. Thanks for sharing your view on this.

      • Moschops Moschops

        I’m not surprised you’ve heard that; it seems to be how the glamour works.

        The classic post on this subject was the “EA Spouse” post, which a quick duckduckgo should turn up. It’s like any field in which people accept payment in glamour.

    • I’ve heard that repeatedly about video game testers, but I haven’t really heard that about the development side.

      • Corey Corey

        As a former games developer, yes it is usually constant crunch mode, mainly because the release date you initially propose (almost always underestimated) can’t be changed because of marketing lead time, and everyone on the team wants to cram as many features into it as possible during that time to hopefully make it AAA. So you need to work longer.

        Also, developers tend to be young without families and don’t have a problem working 80-100 hours a week. And they just don’t realize $60K a year is low for a software engineer, especially when they’re coming out of a college lifestyle where that’s a fortune.

        • Jeff Jeff

          I’m interested in C++ for game dev, but not for a publisher. What’s great these days is that anyone can self-publish to any system; Window & Xbox, Playstation, Android, iOS & MacOS, and Linux. Not one of them is out of reach for independent developers these days.

          My greatest problem is learning the language thoroughly enough. Resources are typically outdated and to abstracted to be applicable in large scale projects. You know, beyond counting and basic comparison.

          I work as a full-time motion graphics artist and have been in the graphic design field for 20+ years now. It’s a difficult task, learning such a deep language without the proper resources.

          Sure there are prebuilt games engines like Unity and Unreal Engine, even CryEngine has some visual scripting ability that makes game dev much easier than it used to be. But the real power is in coding things beyond what the engine was designed for or more specific than what the visual scripting language will let you be.

  11. iyasar iyasar

    Hi,

    It’s really nice article. While i was thinking write such an article i came across with your article, i would like to translate it into turkish if you permit ?

    iyasar

  12. Bill Bill

    Hi Krzysztof! When I read your blog on my mobile, the SNS buttons on the left of the page overlay the text. Hope this can be fixed.

    Great article though. 🙂

    • kszatan kszatan

      OMG, it’s still there? I checked on my phone and it was gone. Thanks, I’ll turn that off and look for some other plugin.
      EDIT: It’s under the post now. I hope it’s not making troubles any longer.

  13. salamanderrake salamanderrake

    Dose anyone know of any good online courses for c++? any type of schooling for it? certificate or degree, I don’t care.

    • salamanderrake salamanderrake

      Nothing C in a C++ compiler type course though please.

    • kszatan kszatan

      Thanks!

  14. Rajesh Rajesh

    Very nice article… good to know about C++ strength.

  15. Wes Bell Wes Bell

    Great article. Another performance sensitive application I’d add to your list is video: encoding, multiplexing, and streaming.

    I’ve been programming in C since 1985 and C++ since 1992. I still love C/C++ for all performance sensitive applications. For super sensitive performance applications, hand tuned Intel assembler was always at least 7 times faster than optimized C/C++ in the 1980’s and 1990’s, in my experience.

    But as always, the biggest performance gains are achieved with lower Big-O complexity algorithms and by leveraging I/O models and techniques built into an operating system. The most dramatic example of the latter is TCP/IP socket communications using Overlapped I/O with Completion Ports. My favorite example of the former is the HxD hex editor written in Pascal by Maël Hörz (https://mh-nexus.de/en/hxd/). No other editor can open multi-GB files instantly or navigate inside multi-GB files as quickly. In email exchanges with Maël Hörz about 10 years ago, I learned his secret was algorithmic.

    Another thing I love about C/C++ is being able to drop down into assembler in the debugger to understand precisely what my code is doing. With an average of once every 2 years, over the last 30 years, I have consistently discovered bugs in Microsoft and GCC compilers and linkers that I would not have been able to understand without being able to drop down into assembly while my code was executing.

  16. Testing Testing

    C+Golang >>> C++

  17. Steve Bob Steve Bob

    C++ is the kind of language you grow to except the way it teaches you it’s ins and outs or you fuck off and play with kiddy crap like Python or Javascript.

    Fact is nothing beats C/C++ when it comes to hard core nudity of baremetal programming. You want to waste time listening to iTunes or do you want to sell that lemonade stand to a bunch of hipsters and move up in the world?

  18. “Cheerful investigating of some old Java code made by a reflection lover.”

    … or some new Java code composed by a BiFunction/Lambda lover.

Leave a Reply

Your email address will not be published. Required fields are marked *