C++ is a language you should give serious consideration to learning in 2019 (or whenever you happen to come across this article). Rapid language modernization, better tooling, a growing and inclusive community, and a thriving job market are just some of the reasons C++ should be your next language to learn.

Wow, this guy drank too much Kool-Aid ™️️, I’m out.

Yeah, I get it. At least in the communities I’ve been a part of over the years, C++ has a consistently bad reputation.

The code is hideous. An unmaintainable mess of paradigms. Unmanaged code? No thank you, I like my feet — sans-holes.

But please hear me out — these comments have some truth to them if we’re talking about pre-C++11. Modern C++ (versions ≥ 11) is an entirely different beast and should be considered separately.

auto genYNames = people | filter(younger_than(39))

| filter(older_than(19))

| transform(names)

| sort()

| unique(); for_each(genYNames, [](auto name) {

cout << name << "

";

});

If you don’t recognize this code as modern C++, then I encourage you to read on and I’ll lay out some reasons why you should reconsider your position on C++ and start learning now.

TL;DR;

— For those of you who need to feel good about not reading.

C++ is reinventing itself in terms of language, community, and tooling. The pace of innovation and language-evolution is astounding. It’s a great time to get into high-performance and systems level programming and take advantage of all the recent advancements. Learn C++, do cool stuff, maybe even get a new job doing it.

Now, go learn something.

Rapid Language Modernization

The C++ that everyone loves to hate is likely pre-C++11. With version 11 came a lot of overdue features that likely address many of the “problems” people point out about the language. A quick rundown of what landed in 11 include:

Smart Pointers — Automatically have your memory cleaned up for you when you’re done using it. Less chances of memory leaks. Three variants were added: unique_ptr , shared_ptr , and weak_ptr . Recently we’ve seen languages such as Rust that try to have smart pointers baked into the language.

— Automatically have your memory cleaned up for you when you’re done using it. Less chances of memory leaks. Three variants were added: , , and . Recently we’ve seen languages such as Rust that try to have smart pointers baked into the language. nullptr — A safer alternative to NULL which removes implicit conversions

— A safer alternative to which removes implicit conversions auto — Automatically deducing variable types

— Automatically deducing variable types Range-based for loops — A modern approach to collection-based iteration (think for x in xs: do ... style)

— A modern approach to collection-based iteration (think style) override and final keywords — Filling in those missing OOP gaps

— Filling in those missing OOP gaps Strongly-typed enums — Moving away from C-style global enums (from LIB_OPTIONS_A to LibOptions::A )

— Moving away from C-style global enums (from to ) Lambdas — Self explanatory to this audience, but yet another example of the modernization of C++

— Self explanatory to this audience, but yet another example of the modernization of C++ static_assert — Allows compile-time checks as a way to increase program safety and security

— Allows compile-time checks as a way to increase program safety and security Move Semantics — Allows proper “ownership models” to be represented in C++. Again we see languages such as Rust that try to bake this into the language itself.

— Allows proper “ownership models” to be represented in C++. Again we see languages such as Rust that try to bake this into the language itself. noexcept — Specifier that indicates the function will not throw an exception (think the opposite of Java’s throws specifier)

— Specifier that indicates the function will not throw an exception (think the opposite of Java’s specifier) std::thread — C++ is a low-level language that targets a LOT of different platforms, so offering standard support for threading is not only a major accomplishment but also a major step forward to modernize the language and reducer barriers to new-comers.

— C++ is a low-level language that targets a LOT of different platforms, so offering standard support for threading is not only a major accomplishment but also a major step forward to modernize the language and reducer barriers to new-comers. constexpr — Allows the compiler (if able for each usage) to fully evaluate a function/expression at compile time. Also has a wonderful side-effect of not allowing undefined behavior.

When you add these features up, you can start to understand why C++11 should be treated as a separate language. It represents a significant leap forward for the language, the standard library, and the preferred style of writing code.

Okay, I can agree that is a lot of improvement. But C++ has been around for a long time, shouldn’t we have made more progress by now?

That’s fair but, I should mention that C++11 came out in 2011. Since then the C++ committee has set the goal to release a new, major version of the language every 3 years. For a mature, stable language that has international standards bodies — this is a big deal. If you’re reading this in 2019 then that means there have been 2 more releases since then — 14 and 17, respectively. And the most notable additions to the language are:

Generic Lambdas — Allows the use of auto as the lambdas parameter(s) for more flexible (re)use.

— Allows the use of as the lambdas parameter(s) for more flexible (re)use. [[deprecated]] Attribute — For API authors to mark functions as deprecated which will result in compiler warnings (optionally with user-defined help messages)

— For API authors to mark functions as deprecated which will result in compiler warnings (optionally with user-defined help messages) Standard User-Defined Literals — Akin to s string interpolation in Scala: "hello"s is a std::string while 60s is a chrono::seconds (many other literals available)

— Akin to string interpolation in Scala: is a while is a (many other literals available) Constexpr Expansions — Ability to use use if constexpr (...) to compile-time evaluate an if block. This feature greatly simplifies and improves meta-programming in C++ (read more).

— Ability to use use to compile-time evaluate an block. This feature greatly simplifies and improves meta-programming in C++ (read more). Structured Binding Declarations — Often referred to as destructuring assignment or pattern-matched assignment in other languages, C++ now supports statements such as auto [a, b] = getTwoReturnValues();

— Often referred to as destructuring assignment or pattern-matched assignment in other languages, C++ now supports statements such as Class Template Argument Deduction — Can now use templates (generics, sort-of) and allow the compiler to determine the type, such as std::pair p(32.5, false) .

— Can now use templates (generics, sort-of) and allow the compiler to determine the type, such as . File System Library — Like std::thread from C++11, the FS lib represents a major step forward in modernizing the language and reducing barriers for newcomers.

— Like from C++11, the FS lib represents a major step forward in modernizing the language and reducing barriers for newcomers. Standard Lib Goodness — The standard library saw many improvements including the addition of std::optional , std::string_view , std::any , parallel container algorithms, std::variant , std::byte , etc.

Well, you’ve certainly made the point that a lot has changed over the past few years. But I’ve heard that if I want to write C++ today, I should really just go learn Rust. It’s more modern and supported by Mozilla.

It is true that Rust is a great language to keep an eye on. But it’s still rather young and adoption isn’t to a point I personally would consider investing my time into (outside of my hobby/fun time 😃). However, Rust has really given the C++ community a good push to improve the language and adopt newer and newer features. LLVM developers have even started working on an experimental borrow-checker (lifetime analyzer), one of Rust’s main selling points over C++. And with C++20 on the way, I believe we’ll see more of the feature-gaps between Rust and C++ closing.

Also keep in mind that C++ is developed by many large companies including 4/5 FAANG companies, Microsoft, and many others. That is to say it’s development is unlikely to slow down as long as there is strong corporate interest.

Community

If you’ve spent time in the C or C++ communities within the last 20 years you might be surprised I’m bringing this up. Recent years have seen some fantastic improvements here. Specifically conferences have greatly improved their social code-of-conduct guidelines and increased presenter and attendant diversity.

A lot of this change is being driven by the #include <C++> group which also runs a welcoming and inviting Discord (that you should totally join). We’ve also witnessed cultural change even at the committee level with the introduction of SG-20, a study-group focused on the “learnability” or “teachability” of C++. The goal of this group is to recommend best practices for teaching C++ to novices and provide input to language feature that may add additional complexity to the language.

The C++ community is also home to an amazing weekly podcast and a ridiculous number of yearly conferences, most of which make their talks freely available on YouTube.

Tooling

Dependency Management

A major, and legitimate, gripe is that managing your dependencies in a C++ application can be a huge headache. Thankfully recent years have seen rising popularity of two C++ package managers; vcpkg from Microsoft (originally targeted just Windows, now runs on Mac + Linux) and conan from JFrog (makers of Artifactory and BinTray). Both of these tools work by hooking into CMake, the near-ubiquitous choice for building C++ applications.

Personally I’m a fan of Conan and every new project starts by plugging it into my CMake files. It makes managing my dependencies as easy as any other popular dependency management system (NPM, Bundler, Cargo, etc).

Code Analyzers

A common critique of the language is that code-safety and resource management can be a challenge, but it’s important to remember that null-pointer exceptions and memory leaks (just to mention a couple) are still possible in “safe” and garbage collected languages. The real question is, what types of tools exist to help you track down those difficult-to-diagnose bugs?

Clang (part of the LLVM project) offers a number of different tools called “sanitizers” which can track down all kinds of memory bugs/leaks, detect data-races, find uses of undefined behavior, and many other classes of bugs. A similar project, Valgrind, offers similar tooling but utilizes a different approach which may be useful for catching different classes of errors. These tools are very, very powerful and some of the best I’ve used having worked professionally with a decent number of languages.

While it may be true that writing C++ can be a “training-wheels off” experience, there is a host of world-class tooling to ensure you don’t crash. 😉

Online Tooling

I don’t know what else to call these, but there are two tools in particular that are indispensable. First is Compiler Explorer — an online tool for viewing compiler output. This is extremely useful if you want to learn what the compiler is doing for you or to troubleshoot code that doesn’t seem to be doing what you expect.

Second up is Quick Bench — an online benchmarking tool. Write your C++ and press run to see how it performs. The tool will also show you hot-spots at the assembly level. Together with Compiler Explorer, you can work to eek out every bit of performance.

Need More?

If what I’ve said so far isn’t enough to convince you, let me quickly remind you that FAANG and other major tech companies use C++ heavily, not to mention almost the entire gaming community. C++ is already deeply ingrained in the programming world, and a rebirth of innovation and community will only serve to strengthen that position.

With C++20 on the horizon now is a great time to dive in and learn more. Ride the wave of innovation; expand your skill-set; and join a growing, welcoming, and safe community of enthusiastic developers.