3 ms·
In fact, with an IDE, this argument is moot. You can have the type anyway. Then, we do use template parameters already, for which we usually don't know the typ
by Ragnarork 12y ago
In fact, with an IDE, this argument is moot. You can have the type anyway.
Then, we do use template parameters already, for which we usually don't know the type. I can't see why we'd bitch about 'auto' and not about the template parameters.
It's just the same thing: coding against interfaces and not implementations.
- JoeAltmaier 12y agoTemplate is explicit; auto can sneak under your radar and look like things you already think you know how they work. Any change to the mainstream syntax can be troublesome at first.
- Ragnarork 12y agoI don't see how auto is less explicit than a template when it comes to involving implicit interfaces.
- millstone 12y agoA key difference is that we are being told to use auto (but not templates) gratuitously, even when there's only one possible type. I prefer to make functions ordinary, and only templatize functions that need to operate on more than one type. There's good reasons for this: the compiler is less effective at type-checking templates, they require the function body to be visible, and they may fail to warn you when passed the wrong type. "auto" suffers from all those problems, and yet we are being told to use it whenever possible. That's bad advice.