r/programming • • Sep 15 '20

Java 15 released!

https://jdk.java.net/15/
214 Upvotes

130 comments sorted by

View all comments

Show parent comments

12

u/Certain_Abroad Sep 15 '20

My colleagues are still afraid of using var

Look on the bright side. Better than that having colleagues who just sprinkle var everywhere.

17

u/Programmdude Sep 15 '20

Var is good when you already know the type.

var x = 0; // Good
var y = new FooBar(); // Good
var z = ProcessRequest(); // Bad

Personally I use resharper (or intellij, webstorm) and so it just inserts the type anyway.

7

u/eeperson Sep 16 '20

Why is the last one bad? The type should just be a mouse over away.

2

u/fuckin_ziggurats Sep 16 '20

The problem with this is code is difficult to read/skim through. When you're working with someone else's code it's very important to be able to skim through code quickly to get to the part that you need. Honestly skimming is half of the work in maintenance projects and bad use of var can make it very difficult.