Today, and not for the first time, I’ve bumped into a description of C++ as “notoriously complex and unforgiving programming language”. Isn’t it strange to define a (modern) programming language, still heavy in use today even on new projects, with adjectives such as these? Would you “sell” your favorite programming language to a fellow software engineer if you’d believe it has these kind of properties?
My 1st encounter with C++ was around 1999, back when I was 16. Till then, I had some short programming experience with C and Pascal (may it rest in peace). Nothing could prepare me to the shock and horror of the first meeting with that language. It sure didn’t help that I had a (really) bad teacher that started the first lesson by using adjectives very similar to the ones used above. Not exactly a good marketing of the language I’d say.
More than a decade later, I’ve been working in the industry on a C project that started incorporating C++ into it. This was my first encounter with (non-modern) C++ outside the academia, and now I know it wasn’t written as a real C++ code, but more like “C with classes”. I found that in too many cases, this is the way this language is treated. It helped me blend in rapidly to the team’s work, without actually learning the language, as I knew C well enough.
Everyone who knows me will tell you it’s not the way I do stuff (I’m a much more rigorous, methodical learner), but time was of the essence, the code was written and reviewed that way already, and I had my own ghosts from the past when it comes to C++ and trying to deal with that obstacle.
Years later, armed with a deep knowledge of the language, what amazed me the most is that on the one hand we interviewed many people to ‘expert C++’ position and on the other hand we didn’t invest in learning the language, its idioms, its intricacies and its new profound updates. Hell, C++ 11 revolutionary version was around for at least 2-3 years but not a single line of production code that I know of, used its new features!
Now I can say that this is not a unique situation to that company. Many companies that I’ve interviewed in later on were reluctant to accept my enthusiasm for modern C++ in general, and advanced template metaprogramming in particular (we’ll get to that topic very soon). Most of them haven’t made the changes necessary to even allow compilation of their code with a modern C++ compliant compiler. Even on 2019, the most advanced, detailed, C++ role description I could find in Israel was asking for C++ 11. Most of them didn’t look for even that.
Even more surprising, on a first, successful interview at a well-known global tech company I coded the solution in modern C++. The interviewer reaction was: ‘wow, I really didn’t think you’ll finish coding the solution with that language, but you did very well’ (there, all candidates must finish coding + testing + refining in exactly 45 minutes, including opening remarks). In addition he said: ‘if you like to have a chance to go through 5-6 interviews next time, I would strongly suggest to abandon this god forsaken language’. And so I did; I relearned Java to be able to work through that interview. Does that sound wrong only to me?
I know, it is more difficult to change a beast. No real updates from 1998 till 2011 have threatened to kill C++ and even the new updates weren’t accepted easily on its community. But I wouldn’t delay on such a detail if I wasn’t convinced that modern C++ is a totally new language. Writing a new project, or even new modules on an existing one with C++ 98 is just inexcusable. So how come tech companies keep avoiding it even now?
I am an old-school learner and I am a perfectionist by nature (No. I don’t tell that in interviews, although it’s true J). Therefore, when learning a new subject deeply, I start by searching for a good book, buy a hard copy of it and read it through, slow and easy. Reading pdf files online always stops at page 12 for me. Can’t deal with all that endless parallel wealth of books in 25 concurrently open tabs or these fast-looking online tutorials :).
Finding a good, comprehensive, readable C++ book took me a lot of time. I’ve started more than 2 dozens of them until I’ve encountered the right one (if I got you interested, have a look at my C++ recommended reading list for 2021 at the end of this article). This is unique to C++. There are a few good ways to teach it but endless bad ways to do that. The bad books and teachers are the ones that are responsible in my opinion to the bad publicity of that language, even now, after all the updates.
Eventually, I changed my perspective on C++ when I got to work on an incredible project. As always, the best way to learn is by experimenting. But more than that – as they say: necessity is the mother of invention. The project necessities brought me deeper and deeper into C++. And as deep as I go into the rabbit hole, the more I got fascinated. The C++ technology I’ve used required me to know templates very well, and very fast the additional development using that technology got me to a real C++ pearl: C++ template metaprogramming (TMP – for deep introduction see this great article).
I don’t know why, but it is considered esoteric and many software companies don’t allow it! Even among C++ professionals, this sub-topic is considered black magic. Most of them would go as far as treating it as ‘bad programming’, just as using goto in C :).
I’ve invested a lot of time solving some difficult problems with TMP (with very little help from google, as there weren’t enough relevant discussions on my problems that I could find). Now I can say that this experience has deepened my love and appreciation of the language. Suddenly it hit me: while I was trying for so many years to tame the beast, I found myself holding a genuine beauty on my hands!
It also taught me something about me that I believe is also true to human nature: once you work hard to deal with a difficult subject, face it and invest in it, the satisfaction of cracking/controlling it, pleases you so much that you now love it. It is evident that good school students love math when they are good at it and hate it when they are lousy at it.
My friends will tell you that few years back I was an advocate against that “notoriously complex, unforgiving” language and would recommend to stay the hell back if asked about it. What’s wrong with Java, Go, Python or even C? Why should we work so hard to understand this beast if it is so hard to handle? C++ is really hard. I know teams that it fitted their needs perfectly but were afraid of the learning curve of the current employees and of new inexperienced employees. Maybe it would break their spirit and make them leave the company.
If that was a singular opinion, I would waive it; the thing is I got the impression that a lot of non-C++ professionals think that way. ‘It’s not worth the while’ they say. ‘The same can be achieved much easily in other languages’. ‘We could write the same code in 10% of the time in Java or 5% in Python’. Now, do they? Is C++ is that redundant and time consuming that most can be achieved with much little effort with a more “modern”, simple language? Or maybe it should be used only on very specific projects like operating systems or databases, where the complexity of the language has enough justification by the cause? What do you think?
I guess I can agree it wouldn’t be my go-to-language for many tasks, but I have seen it in in action with its full glory, and couldn’t find it on any of its newer rivals. C for instance is truly powerful, but always lacked the elegance I found in C++, especially in modern C++. This truly feels like a modern new language, one that unfortunately most companies here don’t value.
My point is that I don’t agree with the argument that a programming language should be easy to pick up for juniors, be used effectively and effortlessly controlled by seniors down the line. Why are so many people willing to make the effort to learn a new database/cloud technology, a machine learning method or even a whole new language, but are reluctant to re-learn their base language and its idioms every few years? Why does it seem to me that a lot of people just wouldn’t take the time to deepen their knowledge with their programming language intricacies and would do that only if it would be specifically demanded from them?
I believe this is the basis to the problem almost everyone has with C++. It just won’t let newcomers to the language (either senior or not) control it immediately. It takes too much effort and has a true learning curve. This is what drawn me away from it for so many years. But does it make it less good? Redundant? Obsolete? What do you guys think?
On the other hand, it got me thinking – is it any good to invest so much time learning hard stuff like TMP? After all it is only a single feature of a single programming language that most professionals ignore. Why should I care? Is the ‘wisdom of the masses’ is right here or is it a true ‘expert’ area in its nature, like a theory in math or computer science?
I might be wrong, but C++ is the only language I know that has a real development committee with community members across the board that study, research and develop in it. Sure, it dropped the ball when the C++ 11 update waited so much. I think they acknowledge it and since then they time the updates very well – once every 3 years, usually with new ideas streamed into community much sooner that the actual release and compiler support. The process works like a Swiss watch and very transparent. Like a factory running standard ISO procedures. Do you know any other programming language handled that way?
What really interests me is having a crystal ball that looks into the future and show how and where C++ will be 20, 50 or 100 years from now. Will it vanish? Will it reshape itself as a more programmer-friendly language (some might comment that it is exactly what happened in 11, 14, 17 & 20 revisions)? Or will it stay that fearful language like today (when an interviewer actually says that staying away from it on the next interviews will benefit you)? Hit the comments if you have an insight on that topic or a hypothesis of the future to come.
I can say that currently I don’t work closely with C++ and it makes it difficult to keep being updated with all the changes. I can also admit that it is easier to forget stuff on that language and get really rusty on the more advanced stuff (e.g.: TMP advanced techniques) after a few months off. This can be a bit frustrating of course. Sometimes I find myself long for that beauty every once in a while, looking back at the time I marveled at another piece of code that is just magic. I truly think that drilling into this language has made me a better software engineer and threw me back to the days of studying theories in academia, where we took the time to learn deeply and we’re less instant-results driven.
Finally, It made me learn new programming paradigms (e.g.: functional programming) and understand much deeper concepts like compile-time vs run-time (wait until you see a database development based on C++ 17 template metaprogramming). I agree there is a great value in learning technologies wider than deeper (a.k.a.: spend time to learn more technologies fast than a deep learning of only one or two), especially in our business. However I find that much more fulfilling to master a new difficult subject, and taming a beast while having it look like a beauty, because beautiful is not always simple. And if you don’t see my point here, just have a look at fractals or Esher stairs.
My suggested C++ reading list for the coming year:
- My favorite go-to C++ book (good also for newcomers with experience from other languages): Professional C++ by Marc Gregoire (5th edition should be out on January 2021 with C++ 20 updates. Current 4th edition contains up to C++ 17).
- C++ Templates: The Complete Guide by David Vandevoorde, Nicolai Josuttis & Douglas Gregor. This is the bible of template metaprogramming, which got new edition after almost 20 years. This book also has many pearls that will help you learn modern C++ much deeper.
- Practical C++ Metaprogramming by Edouard Alligand and Joel Falcou - a great book by the QuasarDB founders exposing advanced metaprogramming techniques.
- Effective modern C++ - by Scott Myers. A must have read for an advanced C++ programmer. His old books are still good as well, but with old C++ version.
- Functional Programming in C++ by Ivan Cukic, to open yourself to functional programming in C++. It’s not just a procedural language or an OOP one.
- C++ Concurrency in Action,2E of Anthony Williams – C++ multithreading is super important this days. It’s a great book on the subject. I would also recommend Intel threading building blocks as a good technology for this stuff.