11 ms·
You don't put auto everywhere. You write out the type in 99% of cases and save auto for 100+ character templated types. There is no reason to to save the liter
by tjoff 9y ago
You don't put auto everywhere. You write out the type in 99% of cases and save auto for 100+ character templated types.
There is no reason to to save the literally 0.2s (you can still spend that time reasoning about your code) it takes to write the type. It is better for yourself writing it and for readability to be explicit.
- joshuamorton 9y agoBy everywhere, I mean where it's otherwise obvious: auto s = "Hello world"; for (auto c: s) { cout << c; } Those autos don't need to exist, they're completely inferable, otherwise you wouldn't use auto. It's not like you can use auto in function declarations, nor should you, I agree.
- tjoff 9y agoI always write std::string etc. in those cases. It is consistent and quicker to read and there is not tangible benefit to using auto.
- joshuamorton 9y agoRight, but my point is that there's really no tangible benefit to writing the type at all. In a language with good type inference (Haskell, ml, modern python), the string literal is known to be a string, and you don't need to do any extra work.