Why you should develop in C++ again

Craig Minihan
2 min readMay 13, 2016

--

In 2011 an unexpected thing happened, well at least I wasn’t expecting it.

C++, the ugly sister development language, feared and loathed by many was reborn, and this time it meant business. There was even a road map: C++14 and C++17 with even funkier features. Welcome back C++.

In the easy 2000’s the development community were sold managed languages as the way forward: Java, C#, Python and others would improve productivity, reduce bugs and offer almost as good performance. Many people dumped their K&R and Stroustrup’s and willingly followed. Java and C# had much simpler and cleaner syntax, managed memory, simple package formats (DLL and JAR) and better development tools — who could argue against it?

In 2014 I started work on a big data project in C#, the plan was to load 100GB+ into memory and query the data set using map/reduce like syntax. It turns out that .NET wasn’t really in a place to handle this type of workload. Almost all standard library functions started to show issues at massive scale which meant a lot of custom code was written to replace collections and other fundamental library features. We even talked about switching to another language since we were now fighting the framework not benefiting from it.

Things were bad, so bad in fact that C++ was suggested without much real enthusiasm. I’d not bothered to keep up with developments in C++ for a very long time so I was totally naive about the seismic changes that had happened since my last #include: threads, regexs, lamdbas, promises, UTF8/16, auto, initializer lists, constexpr, decltype and much more. The C++ language team had looked at Java, C# and many other languages, chosen the best bits and created an incredibly powerful set of new features which put them way ahead of anything else out there. Enough talk, lets have an example:

#include <iostream>
#include <string>
using namespace std;
// func is a bit special
auto func(auto x, auto y) { return x + y; }
int main() {
cout << func(1, 1) << endl;
cout << func(1.1, 2.2) << endl;
cout << func(string{"hello"}, string{" world"}) << endl;
}

The code above shows the use of the C++14 auto keyword in the declaration of the function ‘func’. To the compiler func behaves a bit like a generic or template function. The type of each of the auto parameters and return value is determined at compile time by each reference to the function. So as long as the types of x and y support the + operator we can invoke it with any type we like. This declaration looks more like JavaScript than C++ and is an incredibly simple but powerful language feature which makes writing generic-like code a breeze. You can execute the code yourself here: http://cpp.sh/96e3.

The changes made to C++ in the last 5 years means it should be seriously considered for enterprise software development again. Don’t just default to Java, C# or Python because you’ll be missing out.

--

--