This was linked to ##java a few hours ago and people were absolutely pissed off about it. It seems many members of the Java community see this as a sign of programmer laziness, and there are even others who think type deduction == dynamic typing.
Var makes good code easier to read, and bad code harder to read. So it helps a small amount in the case where you do not really need improvement, and creates problems in the cases where you do.
Local type inference gives you the option to stop saying redundant things over and over again, the typical way Java makes you say the same thing in triplicate:
SomeInevitablyLongNamedThing<Integer> longNamedThing = new SomeInevitablyLongNamedThing<Integer>();
It's noise, and it makes both good and bad code harder to read.
In Scala, my rule of thumb is to ensure that 1) the variable name and 2) the RHS of the assignment, taken together, give a decent indication of the type of the variable, sufficient to understand the intention of the code. If that condition isn't met, I prefer to add explicit type annotation.
If you're worried about making bad code harder to read, my suggestion would be to replace the bad code with good code.
17
u/IronClan Mar 10 '16
This was linked to ##java a few hours ago and people were absolutely pissed off about it. It seems many members of the Java community see this as a sign of programmer laziness, and there are even others who think type deduction == dynamic typing.