4 ms·
I think it was introduced to help with things like lambdas, or other structures that the coder may not know the type of, or it would be difficult to work out th
by sclangdon 8y ago
I think it was introduced to help with things like lambdas, or other structures that the coder may not know the type of, or it would be difficult to work out the type.
Then the usage of auto was expanded to help when writing generic code.
I think both of these cases are valid uses of auto, but people seem to have run away with it and will literally use it for statements like auto i = 0;
As a professional C++ coder, I personally don't have a problem with auto (or var in C# for that matter) but I'd prefer people use it where it's useful rather than for every little thing.
- jzwinck 8y agoI agree, but TFA said: > modern C++ style using auto almost whenever possible. Using auto everywhere, to me, is bad code. It's hard to understand what types we're dealing with, at a glance.
- dingo_bat 8y agoIf you use an IDE, it is very easy to look at the type inferred by auto. So no worrying about types unless you want to.
- mlthoughts2018 8y agoWhat if you’re trying to read the code in a GitHub PR diff? Now I can’t review it because I actually have to go waste time getting the code into some IDE that offers me hovering type info? And what if you use only a console-based editor? Now you gotta abandon the developer tools that work for you because of some language feature? It sounds crazy to me to hear someone say that it’s OK to tolerate the downsides of a language feature because some other tool like an IDE might mitigate them in some cases. Why are we contorting our tools to overcome language problems and acting like it’s OK, instead of designing better languages in the first place that don’t require tooling gymnastics to make them readable?