For everything else, you should pick one of any number of other languages. Rust, swift, zig, go, java, python, javascript. Take your pick.
That’s what Stroustrup does and it works. I just too versatile. Luckily there is recently a push_back against adding new stuff for the sake of it.
My own rules, mine: * Templates are nice. * Template Metaprogramming is not. * Objects and Classes are nice * Inheritance is not.
I like composition and interfaces. I avoid inheritance, aside from some natural cases were it fits (UI Widgets).
I’ve seen in recent years projects switching from C to a mere plain C++. Stronger typing, containers, smart-pointers, simple APIs.
Then you have languages like Rust, Go, Zig, etc which don't have them at all, constructors are just static functions in the namespace of the type, which return an instance of that type.
For the life of me I've never understood why you'd want the former. I'm sure there's a reason, but I never miss it when using languages in the latter category.
The explanation you typically hear is about OO and inheritance, but I don't buy it: If Animal had a ::new() that initialized private state, Cow could have a ::new() too that could call Animal::new() if it wanted, then do further initialization, etc... I don't think there's anything about inheritance that says constructors are a must.
It gives you one of those fat swiss army knives I had as a kid with a spoon, fork, knife, toothpick, saw, nail trimmer, etc. The problem is it's easy to get dirty and the spoon would get locked in place after one use. But it was there, and it worked (once).
C++ is extremely malleable. I think the reason people like it is very similar to the reason people like lisp. That ability to do horrors like make a lisp interpreter with macros or templates is the charm of C++.
And if you are the only one writing it, it can be a joy because there are few limits to what you can or can't do.
It's only when you have to share a codebase with others that things can get out of hand fast without some committee established usage code and pledge.
On your initial look, it looks like a total nightmare.
The more you learn and use it, you learn that it is even worse than you ever imagined
So you try something else and find yourself in a constant loop of “if this were c++ i could just go xyz, by nooo”
So then you love it
raincole•26m ago
This is just a single section of the first chapter of a beginner tutorial. And it's already more things to remember than, say, the whole Lua.
on_the_train•25m ago
01HNNWZ0MV43FF•18m ago
apples_oranges•22m ago
raincole•18m ago
01HNNWZ0MV43FF•18m ago
Did you already know that? Do all your junior C++ programmers know that? Do you have lints turned on in every C++ project and dep for that?
Cause I had to really look at it to figure it out. And I had to think, "Would Rust allow this code?"
William_BB•3m ago
Sure, it'd be nice if the compiler didn't allow you to write this code. But there are worse examples than this out there.
coldpie•14m ago
cogman10•3m ago
chuckadams•19m ago
fnord77•19m ago
tolugenius•11m ago
sobellian•4m ago