(no title)
am17an | 2 months ago
I remember fretting about these rules when reading Scott Meyer's Effective C++11, and then later to realize it's better not to use auto at all. Explicit types are good types
am17an | 2 months ago
I remember fretting about these rules when reading Scott Meyer's Effective C++11, and then later to realize it's better not to use auto at all. Explicit types are good types
guenthert|2 months ago
cjfd|2 months ago
am17an|2 months ago
moregrist|2 months ago
Strong agree here. It's not just because it reduces cognitive load, it's because explicit types allows and requires the compiler to check your work.
Even if this isn't a problem when the code is first written, it's a nice safety belt for when someone does a refactor 6-12 months (or even 5+ years) down the road that changes a type. With auto, in the best case you might end up with 100+ lines of unintelligible error messages. In the worst case the compiler just trudges on and you have some subtle semantic breakage that takes weeks or months to chase down.
The only exceptions I like are iterators (whose types are a pita in C++), and lambda types, where you sometimes don't have any other good options because you can't afford the dynamic dispatch of std::function.
nly|2 months ago
The number of times someone has assigned a return type to int, triggering an implicit conversion.
I'll take "unintelligible compile errors" any day over subtle runtime bugs.
112233|2 months ago
dosshell|2 months ago
maxlybbert|2 months ago
Moldoteck|2 months ago
cjfd|2 months ago
I also prefer not to use auto when getting iterators from STL containers. Often I use a typedef for most STL containers that I use. The one can write MyNiceContainerType::iterator.
spot5010|2 months ago
auto var = FunctionCall(...);
Then, in the IDE, hover over auto to show what the actual type is, and then replace auto with that type. Useful when the type is complicated, or is in some nested namespace.
nly|2 months ago
spacechild1|2 months ago
Really? I've never experienced this myself.