C++ The Good The Bad and The Ugly
Yet another C++ opinion blogpost
In a perfect word every blog should have a post to criticize C++. I personally find myself in a hard situation. I am in my last year of undergraduate school in Applied Mathematics thus am looking for career opportunities and C++ is in demand. So I end up using it and not using it,in the sense that outside of a single file or maybe tiny project C++ you’ll find yourself less productive. It’s still hell to make a GET request in C++ (try it) an it still takes 1 hour to compile project that take less than 6 minutes in Golang (Bitcoin vs BTCd).
To me it’s not really about compile time I like going for a coffee or a walk, to me it’s about being productive and being able to help others with my code. I want my code to be easy to provide to others without having to solve OS-specific dependency problems or having to decide whether “headers only” is good or bad.
The thing is C++ is what Java was in 2000’s it’s an enterprise language. Altough it’s still in heavy use in the numerical departements (almost every Deep Learning or Numerical Library is written in C++) there’s less users of C++ when it comes to newish tech companies and I think this is related to the fact that C++ is counter-productive.
The Good
Starting with good things is always the right thing to do in my opinion. What’s good about C++ well, the following comes to mind :
Generics: yes really that’s the top thing in my opinion that makes C++ worth the try if you’re specialized in the sense that you’re building a program to do one exact thing then stay away from C++ but if you want to prove your data-statics like coding data-structures from scratch the Generics are great. I don’t find a particular use case for them besides this one, I’m not mad-scientist yet to use metaprogramming and don’t feel like it. The only issue with generics is good luck understanding error messages.
STL: Thanks to the Generics we get the STL now here’s the thing, it seems that in places where C++ is used for performance the STL is considered witchcraft some hated piece of dark art that gets reinvented for performance reasons. For you the average programer the STL is great for doing coding contests and the like because you get all data structures ready to be used including some algorithms
Speed : Ahem, well “zero-cost abstraction and what not”.
Libraries : There are a lot of libraries to choose from especially when it comes to doing heavy computations (Armadillo and Eigen are imbeatable) ensmallen is a great library for function optimization for example, there’s also Qt that provides GUI and replacement libraries for some tasks. I doubt you’ll ever find yourself in a place where you have to write something from scratch.
The Ugly
Package Management: Unfortunately this is limbo zone at the same time there are a lot you can pick from and at the same time every C++ developer has an opinion about why other ones sucks I used vcpkg and it was “meh”.
Productivity: If you want to build some kind of general purpose library well good luck, not only you need your code to be portable across compiler but also to build everywhere so you might use CMake then you’ll have to learn their own DSL which comes with it’s own hell. I still use Make to be honest. Build systems tend to receive similar hate as well .
Modularity and Composability: C++17 did bring the filesystem library but not everyone uses C++17 so they use Boost instead, that’s an ugly problem by itself for reasons outside the scope of this post, key takeaway is C++ has evolved for more than 30 years but still use a 44 years technology “Header files”.
The Bad
Well the bad thing is that there are more ways to solve the ugly problem. Should programming languages converge to one set of tooling ? I don’t think so but from a productivity point of view it’s far more fun to have a standard way of doing this than tons of ways to do this, technical debt is real. If you have to learn something new to use it and especially when it goes in the other direction of intuitive then you might be wasting your time.
The usual suspects of why C++ is bad are memory allocation… but even then you really don’t need to explicitly write new even the C++ hooded sect recommends against it.My personal opinion of why C++ is bad is it’s too hard to become productive.
At the end of the day, a programming language is just a tool to solve a problem but it’s often important to choose the right tool. We’re humans after all and we do make mistakes that may lead to catastrophic bugs, but when the language helps you defend against such issues then you’re more likely to become productive. In my case the tool I use should help me move forward not fight me and make me want to throw this out of the window and go herd like in the old days.
Takeaways
My personal key takeaways are these :
- First, this is really a personal post. I am not evangelizing for other langues but check them either way .
- Second, your sanity is worth more and yes CMake is difficult to use and yes compiler errors only get easy to decipher with experience.
- Third, productivity is not a particular caracteristic take a look at Github trends for Golang and Rust or even Elixir when a language helps the user, the user helps the language.
Last but not least,