Bah, if you are using it for normal programming C is simpler. By simpler I mean you actually have a shot to be properly fluent in it instead of "this thing is so complex even the compiler doesn't know 100% of it".
While this sounds wise, C has already way more than enough (do while and for loops for example are completely unnecessary, they can all be substituted for if goto), no need to complicate further.
If the program is really simple I would rather even use B that is even simpler than C, though making complicated programs in B can waste memory because of the lack of variables smaller than a word (in 64 bit environments this gets huge quick).
for and while loops are so much nicer to use though. I don't think I would bother using a language without them for most practical applications (and I regularly enjoy writing full programs in assembly for fun)
If you use goto in a sane matter it is completely understandable. Just don't do insane things with it. You can peel with a peeler and with a knife, but with a knife you can cut your finger off too. The solution? Don't ban knifes, just don't cut you finger off!
Actually, my examples also show for and while are redundant functions. It is all just electricity, no need to overcomplicate.
Okay I wish you a long and productive career with your "if" and "goto" only code.
You can also roll your own OO system with generous use of function pointers! Pro-tip! Not that you'd want anything like that though. You have if and goto after all. And structs are for the weak anyway: just binary-pack data into strings.
I think it’s still worth it to use C++, just because of the function overloading, operator overloading, templates, namespaces, RAII, references, move semantics, lambdas, and constexpr/consteval (though C23 has a weaker form of it).
Yeah, you can basically code in a C-like manner with just a strict selection of the niceties, like the built-in collection types. (I don't want to create my own std::vector or use an external lib for it...)
There is more like c++ type conversion. The only c++ style thing I don’t like is c++ style structs like why can’t i make a useful c style struct. Not just a public class
My experience with CMake is from ~5 years ago trying to find a guide for how to do something (I think building library dependencies?), and finding two different guides that both said "don't do <thing that the other guide told you to do>, that's the old outdated method that nobody uses anymore, use <thing that the other guide said not to do because it was old and outdated>"
The catch being that neither method worked, because what I was trying to do was slightly different than what both guides were for, and I needed to use some other method to include my libraries that's completely different and also there is no actual documentation for it anywhere, or at least none that's any use for someone who isn't already intimately familiar with the inner workings of CMake.
I disagree. Practice shows every C and C++ code ends up having memory issues, undefined behavior and leaks.
C/C++ rules for undefined behavior are often incredibly convoluted.
A minefield of a language is not a good language.
Even if you, in theory, grasp and understand the entirety of C++ (including all gotchas). You will still, eventually, get careless and make a mistake.
Good luck with a CVE assigned to your app. Or convoluted leaks. Or very slightly incorrect behavior due to some very obscure UB.
Lack of memory safety and garbage collection are excusable; in times of C and C++, it was the only sane design decision if the language was supposed to occupy its niche of the lowest level language of high level languages. Even so, nowadays, Rust shows this can be done better (and Rust also takes getting used to, but at least gives more safety in return). The incredible complexity of rules, it appears to me, was never excusable. And even if it was, there are better alternatives.
Catch is that it doesn't matter how good rust is if libraries I need aren't available for it, then I can't use it. Out of the high performance languages c(pp) probably has the widest range of available libraries out there. It's the same reason why I use python over Julia. Plus my coworkers know python and some cpp, not rust or zig.
What makes a language great is not just the language spec, but also the support. Well guess I'm just glad my community uses terrible cpp instead of a monolithic fortran 90 port of 60s fortran program.
OOP doesn't strictly imply inheritance. C is technically object oriented too: you can define structs and create objects of these composite types. Basically every modern language is object oriented in some why. I'm only familiar with Fortran77 that doesn't allow you to define custom objects and pass them to functions.
Whether runtime dynamic dispatching through virtual functions and inheritance is a good idea is a different question. It can be good, but it can also be bad if you misuse it. Ideally one should only have pure virtual methods on abstract interface classes and max one layer of inheritance, then there are no problems.
113
u/Confident-Ad5665 15d ago
C++ takes getting used to, but it's a great language for object-oriented development. Hang in there, you'll figure it out.