Why (modern) C++ and why now?

The programming language C++ needs no introduction. It has been in the 4th position of the popularity index as long as we know about popularity indexes. It is one of the goto languages for accessing raw computing power and resources. Why hasn't it become everybody's daily driver, and why should you prefer it at least as your secondary programming language? Let us explore that.

The power of C++ still dominates

Popularity means how widely it is used or looked for and doesn't necessarily mean how much loved. C++ is also the 8th most dreaded programming language. However, those who mastered and wielded this programming language have built a bedrock of high performance compute stack for the rest of the industry. C++ is used to create operating systems, browsers, V8 engine, and all that run on top of it, networking apps, cloud function/lambda engines, databases, caching, programs for rockets, games and the list remains forever incomplete.

The software and services are built, stitching many smaller libraries, packages, components, and their dependencies together. Imagine each of those components not accessing what modern computing infrastructure has to offer. The world we know it could have been way too slow.

What is Modern C++?

The syntax of C++ puts people off. It is so archaic, and you have to know systems-level details to take full advantage of it. The syntax has gotten way better in modern C++. C++ is considered "modern" if the language specifications you are using is 11 onwards, (eg. C++ 11, 13, 17, 20, 23, etc.). Every 3-year the C++ committee agrees on the language improvements, and these specifications are always backward compatible. Whatever you are going to write today will remain functional in the future.

Better constant declaration, algorithms and lambda with scope management:

// Modern C++ way of declaring constants, forget: #define X Y
constexpr int LOWER_LIMIT = 2, HIGHER_LIMIT = 4;
vector<int> collection{1, 2, 3, 4, 5};

cout << "\nUsing Modern C++ lambda: ";
auto result = find_if(begin(collection), end(collection), [](int i) {
  return i > LOWER_LIMIT && i < HIGHER_LIMIT;
});

cout << *result << endl;

Unified way of variable declaration, auto and index-free iterator:

struct Country
{
  string Name, Capital;
};

cout << "Using C-style: " << endl;
vector<Country> countries;
Country c1 = {Name : "Russia", Capital : "Moscow"};
countries.push_back(c1);
countries.push_back({"China", "Beijing"});
countries.push_back({Name : "Greece", Capital : "Athens"});

for (int i = 0; i < countries.size(); ++i)
  cout << countries[i].Name << " 🏛️ " << countries[i].Capital << endl;

// Modern C++: unified way of declaring variables
Country c2{Name : "Canada", Capital : "Ottawa"};
vector<Country> countries2{c2, {"Egypt", "Cairo"}, {"Turkey", "Ankara"}};

cout << "\nModern C++ index-free iterator:\n";
for (auto country : countries2)
  cout << country.Name << " 🏛️ " << country.Capital << endl;

Smart pointers, move semantics, parallel versions of the Standard Template Library, etc. many other improved features for better and more concise programming are new in Modern C++, which we may cover in some other posts in the future.

I joined the workforce circa 2005, and that was when rapid application development was all the rage in line of business application (LoB) development. C++ was possibly the 4th language I learned at that time, and the syntax didn't scream productivity at all. I used Turbo C++ 4.5 and Qt (Mandrake Linux), and possibly C++ 98 to build tiny apps. Modern C++ has come a very long way for me to consider learning and to use it again.

Evergreen benefits of C++

The following is by no means a complete list of C++ advantages that I am considering choosing to relearn as my secondary programming language.

  • The specifications are used to build C++ compilers. There are several of them for you to choose from. For example, Visual C++ (Windows), CLang C++ (OSX), GNU C++ (all OSes), etc. In most cases, you can just pick one according to your OS.
  • Cross compile for any computing platform, such as ARM, x86, Raspberry Pi, desktops, notebooks, tablets, phones, etc.
  • C++ programs never run over a virtual machine, e.g., JVM/.NET Framework, so they don't have garbage collection, e.g., Go has garbage collection. Also, it means you have to take care of a few things manually.
  • The sheer amount of content on C++ and the userbase are astounding.
  • Many developers are already familiar with C-family languages, such as JavaScript, C#, PHP, Java, and C.
  • ISO standardizes C++ specifications
  • A 35-year old programming language that is the fastest growing programming language in September 2020!
  • Nearly as fast as C

Conclusion

There are more modern alternatives like Rust, Go, sure, but the world speaks in C++. If your background is C-family of languages, you will feel right at home with the Modern C++, compared to, let us say, learning Rust or Go, quite different syntax and language constructs. C++ is probably the best programming language for revising Computer Science basics after 15 years in business apps development.

Next post: Lets get the Hello C++ out of the way!