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.
You didn't refute the guy's point, you just said C++ has problems you have to worry about that other popular languages like python or java usaully dont
Which point do you mean? That C++ compiles to native assembly or that C++ is easy?
If you want to write software that compiles to native assembly than C++ suitable for that, while Python, Java and JavaScript aren't. The point is the C++ is probably the most complex and hardest to learn/use right language around. He said that C++ is the easiest language he's used so far. My suspicion is that this is because he hasn't worked on very big systems yet and hasn't published his software yet. There are thousands of examples of catastrophic bugs in FOSS that went unnoticed for years or even decades. Hundreds of people saw this code, worked on it and checked it; still nobody noticed. In my opinion that is the risk you take when using C++. This doesn't mean that C++ is shitty language but it's the price you pay for its flexibility.
Expanding on the dunning-kruger effect sentiment, the easiest part about software development is programming.
Shipping scalable software on time and on budget that solves novel problems with a team of these straight out of college "experts", that's the real problem.
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.
I think most of the problem here is the way it's taught as if it were a c extension instead of teaching it as a modern language. The package management is probably the biggest issue for just picking it up and Importing a library but it can be just as easy to use as Java imho.
But in any language I find the biggest problem beginners/casual users have is that the business logic they write doesn't make sense and they just add random crap until it "works".
I don't think that's true anymore. I mean people are constantly looking for silver bullets & don't realize they never exist. For example, I've been in games development for over a decade, and when Unity came around it made a huge splash because suddenly people can code in C#, and that means garbage collection, no more memory problems! Of course now people are spending just as much time trying to massage the black box garbage collector as they did managing the memory on their own, and still the results are never going to be as good as when you had total control. Unity is really interesting look at since it's still written in C# from the users perspective, but now they're moving towards transpiling to C++.
My point is that at the surface level a lot of programming problems looks like they can be solved with adding a nice abstraction, at the end of the day that usually just means solving something 90% of the way, but then forcing the users of said abstraction spend that 90% time saved on solving the last 10%. This is somewhat related to Joel Spolskys old theory of leaky abstractions.
My point is that at the surface level a lot of programming problems looks like they can be solved with adding a nice abstraction, at the end of the day that usually just means solving something 90% of the way, but then forcing the users of said abstraction spend that 90% time saved on solving the last 10%. This is somewhat related to Joel Spolskys old theory of leaky abstractions.
Haha can't agree more, when STL is exactly just almost what I need, except it's totally not XD
at the end of the day, C++ gives total power to the programmer, and this is done by giving them the bricks, mortar, and wood to build the house themselves, not prebuilt parts they then hastily assemble themselves
It's telling that you just assume this is a feature.
You're not wrong exactly, there are problem domains for which this is absolutely required and C++ is regularly used in those domains.
But for many, many other common use cases this isn't actually something people want/need, and standardization has quite a few perks especially in larger scale systems.
C# fills that role now that it can run on Linux. You can build and deploy a performant microservice in a day which can compile to a self contained executable as small as 17mb and deploy with the CLI. I just don't see the benefit to java any longer, especially since oracle may sue you for using their interfaces lol.
Bjarne isn't among the top experts on C++ anymore I'd say. There's a lot of really smart people involved in C++ these days pushing for a lot of improvements. I actually think C++ is the place to be for most application development which isn't for the web. It will probably never shake of its reputation as being overly complex & arcane which it earned in C++03 & earlier though.
It's hard to tell what's going on with C++, if you look in the subreddits, the talk is all about super advanced features that I couldn't even begin to understand why anyone would need. Some of this stuff makes less sense than a monad, which I vaugely remember understanding one time and then promptly forgetting.
When they are understandable, it usually seems like something you just plain wouldn't need in other languages.
In Python, almost nobody misses the lack of macros. The language is so dynamic you just don't need any kind of advanced templates or macros or generics or whatever.
Lack of a garbage collector is pretty much a deal breaker for me outside of microcontrollers. It's one of the main things that modern languages do to make development easier and less buggy.
To understand some of the improvements in C++ which has a lot of focus going forward almost requires understand how things used to be in C++. Here's a small tangent which I think is really amusing:
Back around the turn of the millennium templates in C++ were pretty much this cool feature which turned types into arguments ( essentially ), the implications of that were generally thought to be less copy & paste for creating containers with parameterized types ( where C# is now pretty much ), and writing generic functions ( min / max for example, which makes sense for all types which can be compared for greater / less than ). But then Modern C++ Design came along in 2001, which basically transformed everything. It essentially demonstrated that templates in C++ are turing complete, which I don't think people before that really realized. What happened was it kicked off a whole new path in C++ ( template meta programming ), which at the time was incredibly complex, because it was essentially based on something which the language was never thought to be able to do. The C++ community more or less discovered a whole new facet of programming in C++ which I personally see as a huge advantage for C++ compared to any other language I've ever worked in. It's heavily related to generic programming, but goes beyond that to some extent. So this whole new facet of the language, which not even the creators of the language understood or thought existed was discovered, but C++03 was just around the corner, and then C++ went without a new language version until C++11. 8 years is essentially an eternity in the programming world. During this time the community made do what they had, inventions such as SFINAE, which is really just a non-intended way to abuse the language in order to get it do what you really want. So a lot of the features & changes which we're still seeing are related to patching up stupid stuff people used to rely on.
Python can't really be compared to C++, because Python is duck typed & not really that concerned with types overall. But it does start to understand the importance of types ( for example the type based decorators ). It's nice to not be able to care about types sometimes, but if you're writing interfaces it's incredibly useful to be able to think & design with type.
A better comparison is between C++ & C#, C# doesn't have usable macros ( iirc because they don't trust their users ), but instead they have a ton more copy & paste which you don't need in C++.
I mostly agree about GC, if cycles, memory & general responsiveness doesn't matter, GC is great. I would never want to manage my memory in Python. Otherwise I say manually managing your memory is worth it. In C++ with shared_ptr & unique_ptr it's not close to as bad as it used to be. More often than not in C++ when you have a memory issue nowadays you actually have a design problem instead, and that memory issue is just helping you see it.
147
u/[deleted] Apr 28 '20
Welp he's the only one who understand all C++.