Statically, not much is going to change from this, so that's fine, but it's still going to hurt readability if you're assigning new variables from method returns that aren't immediately obvious. It's good and cool to know right away that this variable I'm looking at is going to be a String -- because it's been declared explicitly -- rather than the implicit case where you have to jump to the method signature to figure out what's being returned.
You're not always going to be looking at code through an IDE, though (i.e. if I'm looking at a code review on GitHib, which honestly makes up a lot of my time spent), and for large projects, the indexing that makes that happen can be painfully slow and sluggish to use (I'm looking at you, Eclipse). And either way, it's always going to be better for readability if the information I need is right there on the screen for you, not hidden behind clicks and interaction with the IDE.
Its a continuum of how much information is hidden without going to the implementation. A lot of the time knowing the type won't help that much anyway. So:
are equally obscure without going to the definition if you aren't already familiar with the code. I find it to be the exception not the rule that the implicit declaration is what makes the code unclear.
With the explicit type I only have to know what a CustomerValidationResponse is.
No, because it might return a type that is implicitely convertible to CustomerValidationResponse and where the conversion has side-effects. So you still have to check it, while in the var case you know that the variable is of the type of the return of the function.
I have been of the opinion in c++, that if the type isn't obvious then you shouldn't use auto. That doesn't mean auto isn't useful iterators are horrible to write, using auto it = myVector.begin(); makes it alot more pleasant to both read and write. However I would use std::string result = aClass->someFunc(); Best of both worlds but getting people to adhere to it can be a nightmare.
"But you can use it to write bad code" is always the argument against introducing a language feature. It doesn't matter which feature. Someone will say it's a bad idea because you can write bad code with it.
Guess what? You can do that with any feature. It's a bad argument.
"It encourages bad code" is a reason against introducing a language feature. Even for things that are controversially bad (i.e. not everyone agrees they're bad).
14
u/lamarf Mar 09 '16
Statically, not much is going to change from this, so that's fine, but it's still going to hurt readability if you're assigning new variables from method returns that aren't immediately obvious. It's good and cool to know right away that this variable I'm looking at is going to be a String -- because it's been declared explicitly -- rather than the implicit case where you have to jump to the method signature to figure out what's being returned.