Hacker News new | ask | show | jobs
by roel_v 4483 days ago
It's for iterators, and similar template-heavy types, that you need them the most. Well not for an iterator over an std::vector<double> obviously, but the worse the amount of typing for the type gets, the more you need to know the actual type to save you from having to do the type deduction in your head every time. (well not 'you' in the sense of 'the author', the whole problem it's that it's the people who need to read the code afterwards need the full type the most, the incentives are so misaligned).

I guess the more I think about it, that that's what scares me the most about 'auto' - instead of having the original author do the type deduction once (which is something he intended in the first place, hopefully), you now (as a maintainer) have to go chase it down, just to save the original author from typing out a hairy type.

Now I do realize the real use case for 'auto' - it's the cases where you don't actually know the type yet, because you're providing an extensible framework through template specialization. I have written quite a bit of such code myself. And yet, despite having suffered through all the 5-line typedefs that that sometimes required, I'd be willing to keep doing that to save myself from code by people who mistake 'auto' for a convenient way to save a few keystrokes (this is not meant as a jab at the parent, I'm just talking in general, in case anyone would interpret me wrong).

1 comments

Auto is useful to reduce the amount of typing and DRY principle. Your arguments are meaningless when you can hover the mouse on the "auto" keyword and have Visual Studio/Eclipse tell you its type.