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

74

u/evil_burrito Mar 09 '16 edited Mar 10 '16

I think one of the problems of untyped or weakly-typed languages is that they can be difficult to debug or understand somebody else's code.

I'm a fan of strong typing. I doubt that puts me in the majority here.

Edit: I'm simply stating a personal preference here: I think this will decrease the readability of source code. We don't all have to agree.

Edit: I can see how my original comment was poorly worded. I didn't mean to say, "I think this change will make Java less than a strongly-typed language", I meant to say, "I think this change might make Java read like less than a strongly-typed language".

12

u/SikhGamer Mar 09 '16

This was my argument but then actually using var in production with C# and it honestly wasn't a problem. You still have the option to strongly type it if you want, but var does make everything more readable.

And var foo = someObject.method(); isn't as hard as you think. Visual Studio allows you to change var into it's strongly typed counter part with R#. Inspecting the method would reveal the return type too.

What I learned among the way was that I wasn't too concerned with what it was returning but rather what it was doing.

7

u/Zarlon Mar 09 '16

Exactly. Anyone who've coded C# more than 2 hours realize the beauty of var. R#, or lint for that sake, can take care of bad coding practices.