Originally Posted by
Mario F.
However, I believe auto is an accident waiting to happen. For one, you lose semantical expressiveness and you make the code logic harder to follow. auto almost feels like I'm wanting to program in a non typed system; i.e. "I don't know the type, I just know it's some form of X, I can't bothered checking the library documentation, or it is too long to type, so I go with auto. This will work."
It's not like a type error could occur, you're just relieved of having to express the exact type name (which is usually irrelevant anyway).
And many uses of "auto" can already be simulated.
Code:
void func1()
{
auto f = boost::bind(... some crazy complex binder ...);
// Do something repeatedly with f
}
Without auto you'd be reduced to figuring out the exact type of the complex bind expression. OR, you could add a level of indirection to allow the compiler's type deduction to do things for you:
Code:
void func2()
{
with_f(boost::bind(...))
}
template <typename F>
void with_f(F func_p)
{
// Do something repeatedly with func_p
...
// Declare other instances
F a, b, c;
}
So it becomes clear that the "hiddenness" of the actual type name is no different than how a type name is hidden by a template function. Again, you don't care what F is, you just want to be able to refer to that type easily.