r/java • • Mar 09 '16

var keyword proposed for Java

http://openjdk.java.net/jeps/286
240 Upvotes

312 comments sorted by

View all comments

26

u/xhak Mar 09 '16

No thanks, the few keystrokes are worth the clarity.

23

u/ElvishJerricco Mar 09 '16

Coming from Haskell, I feel there's something people often overlook when bashing type inference. In Haskell, the type inference is better than just about any other language. And yet, we still explicitly type every single top level function. It is absolutely worth the clarity to explicitly type things used outside the current scope.

But most of the time, when something is only being used locally, the type is very clear to the reader, because it's definition is right there. And even locally, type inference is only preferred to explicit typing when the inferred type is painfully obvious. For example, a = b + c, when b and c are known to be Int. There's zero added clarity by explicitly typing a. It's totally obvious what a's type is.

So yea, inference is bad when something's type wouldn't be obvious. But when it is, the lack of inference needlessly gets in the way.

-5

u/xhak Mar 10 '16

People underestimate the number of shitty java devs out there, writing the most obscure dumb code that works more by accident than anything. A great feature of java is that it enforces and encourages some verbosity that is very helpful in these situations. Undercutting these is a loss to the language's appeal in my opinion.