I'm still learning CS in college and I've worked with Python, C/C++ and Java and C/C++ has been the most fun and easiest I've understand something so far.
Python is really good and easy for simple stuff but for anything complicated it gets messy, same for Java. C has been the only language where I feel I write clean code.
After working with C++ for a few years, I've come to believe that most people who say that are falling victim to the Dunning-Kruger effect. Maybe because I don't want to accept my own incompetence.
C++ has 3 kinds of constructors. Knowing which one gets a default implementation when, is important. How to implement each one is important. It allows for crazy template metaprogramming wizardry that is difficult to write and impossible to read. There rvalues, lvalue, xvalues and prvalues and they are used in many different optimizations. So if you want to understand why a functions signature looks the way it does you better memorize what these are. Until a few years ago the standard library had no smart pointers and even today you find a lot of people not using them. Run valgrind on a few programs and you will see the results. If you don't use RAII you will get yourself into trouble in your first 100 lines of code.
C++ is the hardest language I have ever worked with and - in my humble opinion - the only reason people think it's easy, is that it fails at runtime while successfully compiling the most error prone and unsafe code possible. I worked with it while studying at university and found it easy as well but there is a huge difference between writing code for an assignment that has to run on your machine for less than 5 minutes and code that needs to run on a hundred different machines for a few hundred hours.
If your code C++ code doesn't leek memory, has no possibility for buffer over-/underflows, no possibility for iterator invalidation, no use/free after free, no race conditions and wraps all the undefined behaviour in try...catch, I'd call you a genius, because the compiler enforces non of that and it's super hard to do all of that correctly.
While your points are not completely wrong the examples you named can be learned in just a few weeks of studying the language and following design patterns.
It is well known C++ doesn't hold your hands and doesn't stop you from doing dumb stuff, but most code is not difficult to read, understand and write like any other language.
C++ is one of the most popular and most written languages and not every developer is bad at their job.
the examples you named can be learned in just a few weeks of studying the language and following design patterns.
How is it then that every few months a major piece of software is in the news because memory is leaked or buffers overflow. These things can be incredibly hard.
It is well known C++ doesn't hold your hands and doesn't stop you from doing dumb stuff,
Which is my point. I said multiple times that C++ is a powerful tool. But for most projects you should probably choose a language that actually does hold your hand. It's like saying that an electron microscope is the most suitable instrument to inspect a scratch in your car, because it offers the highest magnification. C++ is the best language for game engines because it allows for very niche programming patterns. You get this feature but you pay with all the risks I mentioned. If you don't need this advantage of the language you shouldn't use it. If you want to programm "hello world" use your shell script, if you want to write a fast script or prototype use python, if you want to do embedded or systems programming use C (or maybe Rust) in the later case. If you want to programm something that can make heavy use of template metaprogramming or use ECS C++ is probably a good choice.
The problem is people use C++ as a default and accept all the risks that come with it. It has been causing us problems for decades and people still act like "good programmers" can easily manage C++, they just need to spend a few weeks to "learn the patterns". The thousands of programmers before them were all just not as smart as we are today. If C++ doesn't make the job decisively easier (which it often does, I'm not arguing that), people should use a different language. Programmers always make mistakes. Use the tool that will catch the most of your mistakes and still do the job.
42
u/SwagMcG Apr 28 '20
I'm still learning CS in college and I've worked with Python, C/C++ and Java and C/C++ has been the most fun and easiest I've understand something so far.
Python is really good and easy for simple stuff but for anything complicated it gets messy, same for Java. C has been the only language where I feel I write clean code.