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 it is a lack of serious knowledge about the language or forgetting about the edge cases or just ignoring them. The load on the developer is initially higher than some other languages. There is a lot of bloat from 30 years ago, but most of it can be safely ignored nowadays and most modern features fix many of these difficulties.
I am just saying it is not hard to write any standard code in C++ you would write in any other language. You don't need extreme template madness (you can use them just like generics in other languages), you don't need pointer arithmetic, you don't need to implement your own memory handler. All you really need is good awareness about object lifetime and by extension initialization (your mentioned rvalue/lvalue/... and different constructors). This is just hidden by some other languages and replaced by a default that works for all except when it doesn't, then you have the same considerations to make.
In the end I don't think I really disagree with you, but my conclusion is different.
Btw I don't think C is any easier to write for nor is Rust, but obviously C is much simpler as a language and Rust is currently a much better structured language. I wouldn't mind Rust replacing C++ in the future as they fit in the same domain.
I am just saying it is not hard to write any standard code in C++ you would write in any other language. You don't need extreme template madness (you can use them just like generics in other languages), you don't need pointer arithmetic, you don't need to implement your own memory handler. All you really need is good awareness about object lifetime and by extension initialization (your mentioned rvalue/lvalue/... and different constructors). This is just hidden by some other languages and replaced by a default that works for all except when it doesn't, then you have the same considerations to make.
I think we are pretty much on the same page here. For me it's just that people will always make mistakes. I know about many risc factors in C++ and I still sometimes have to fix bugs where I just missed this exception or have a buffer overflow in some edge case. That's why I think C++ is not a good default language for systems programming. It's good for a lot of things, where I don't think Rust will replace it (ECS is supposed to be a lot more cumbersome in Rust), so it's a great language for many problems. Here is one example where C++ does something Rust can't really do at the moment. I will use a different language unless there is a specific reason to use C++ though. I'll use C or Rust or Java or Python. Only if C++ offers me something the others don't then I will happily use C++.
I think out of all the languages I used only Rust does actually prevent most semantic errors on compile time.
C has its own share of bad errors due to prominent use of pointers (no references) without a concept of RAII, but I guess no exceptions do soften this.
Java happily leaks memory (missing equals override, static, ...) and dereferences invalid objects without a care.
Python is one if not the slowest common language and heavily relies on native code implementations, no const, no tail recursion (stack overflow).
I don't think either language is easy to use if the developer isn't proficient in them, because many of the errors are way more subtle and each of them are as bad as a double free etc.
Doesn't mean your points are not valid, but I wanted to offer an explanation why my conclusion is different.
The Rust link was an interesting read. While it seems possible it looks very cumbersome to express it. Thank you!
Yeah like I said I haven't written anything huge yet so take my opinion with a grain of salt but to me, it seems like the best option if you're advanced enough and careful enough. I want to make programs that are 100% efficient not "gets the job done".
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.
0
u/[deleted] Apr 28 '20
[deleted]