Hacker News new | ask | show | jobs
by advisedwang 809 days ago
Explicit typing is great until your code is littered with shared_ptr<vector<shared_ptr<map<string,T>>>> everywhere.
5 comments

If you're using a type like that repeatedly then it probably deserves an alias.
Every time you want to iterate over a map, for example, you're using std::pair<T,U> or std::unordered_map<T,U>::iterator. This gets very annoying without auto, and making an alias doesn't really address any of the complaints the article has.
The issues around type inference could be an annotation (extra overhead) on a function or line to enable some form of it, for simplicity of mapping or conversion, but leave it out by default. Now you get the best of both worlds.
Aliases have their own problems. You may have to propagate the alias, or define different aliases with the same type all over the place. Then you have issues with changing code.

Complex composed types just have this issue to be honest, and personally I like having inference as a tool to avoid the litter.

But the bad news, then, is all that complexity is hidden, metastasising
Exactly. Just because you don't have to read it, doesn't mean it isn't there. It's still there, just hidden from you, and worse now you have less incentive to actually simplify it...
Yeah. “Auto” was probably one of the best additions to C++ ever.
When trying to figure out something's type is the same as trying to fully comprehend a regex pattern, you know things have gone too far.
Yeah, I think he hasn’t programmed Java.