> Adding “auto” is just a me-too to the “var” of C# and Java.
I get the "C++ is so full of nonsense, and they keep adding more of it!" attitude, and I largely agree with it, but "auto" is a bad target. auto makes a lot of c++ code (most, arguably) much easier to read and cleans up and simplifies a lot of the language. Like, the fact that you never, ever, have to write out the full name of iterator types in C++ (you can just go "auto it = vec.begin()" or whatever) is worth the feature all on its own. It also makes dealing with complex generics simpler. It's a huge quality of life improvement.
There's a reason most languages have added type inference, and it's not just a trendy bandwagon. In most reasonably recent languages (Rust and Swift notably), it is in fact the default to do this kind of type inference. It's genuinely a nicer way to program.
In C++ it also serves another important purpose: if there wasn't auto, there wouldn't be lambdas. All lambdas in C++ have an type created by the compiler which you can't access the name of. In order to store a lambda in its native type, you therefore have to use auto. Basically, if you like that C++ is becoming "more functional", that is only really possible because of adding auto.
Agreed. Another way to think about it is the language is trying to get the compiler to do most of the heavy lifting. Stuff like auto makes sense with this attitude because why have the programmer think about what the type should be when it can be infered by the compiler? Also see templating.
I've come back to C++ after being away from it for a few years, and modern C++ (17, 20) is a delight to work with compared to what we had in the 90s. RAII especially...
I get the "C++ is so full of nonsense, and they keep adding more of it!" attitude, and I largely agree with it, but "auto" is a bad target. auto makes a lot of c++ code (most, arguably) much easier to read and cleans up and simplifies a lot of the language. Like, the fact that you never, ever, have to write out the full name of iterator types in C++ (you can just go "auto it = vec.begin()" or whatever) is worth the feature all on its own. It also makes dealing with complex generics simpler. It's a huge quality of life improvement.
There's a reason most languages have added type inference, and it's not just a trendy bandwagon. In most reasonably recent languages (Rust and Swift notably), it is in fact the default to do this kind of type inference. It's genuinely a nicer way to program.
In C++ it also serves another important purpose: if there wasn't auto, there wouldn't be lambdas. All lambdas in C++ have an type created by the compiler which you can't access the name of. In order to store a lambda in its native type, you therefore have to use auto. Basically, if you like that C++ is becoming "more functional", that is only really possible because of adding auto.