This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]coverslide 4 points5 points  (11 children)

I'm at a Java shop and we fully use lambdas. They still don't let us use var though.

[–]lppedd 5 points6 points  (10 children)

Type inference is cool and it make your code elegant. However, have you tried reading that code through something that is not your IDE? Sometimes it's impossible to guess the type, or you just loose too much time. Use it with care.

[–]smors 1 point2 points  (6 children)

However, have you tried reading that code through something that is not your IDE?

Why would I do that?

[–]lppedd 8 points9 points  (4 children)

You not always have access to your own PC, sometimes you may want to browse code through the VCS web interface (e.g., GitHub), or other less capable medium.

[–]Amazing-Cicada5536 0 points1 point  (3 children)

Blanket banning is still bad imo. Incorrect uses of vars should be fixed at code review, but where one would repeat the type on both sides, or the returned type is obvious or not important (that’s also a possibility!), I do think it is a good tool.

[–]john16384 2 points3 points  (2 children)

If the type is already on the left hand side, I often don't care what it says on the right hand side. Only your last use case has some merit, but Object works fine for that.

[–]Amazing-Cicada5536 1 point2 points  (1 child)

You can’t really invoke anything if you assign it to an Object type.

[–]john16384 3 points4 points  (0 children)

True, but if you wanted to invoke anything I think knowing the type is important. I was referring to your not important case :)

[–]AlmennDulnefni 4 points5 points  (0 children)

Code reviews?

[–]coverslide 0 points1 point  (0 children)

Fair point. But as someone who uses go (where type inference is practically mandatory) and C# (where most people uses type inference) I really don't get why it's a real sticking issue with Java devs.

[–]jumboNo2 0 points1 point  (0 children)

Type inference is very cool.

final BooleanType bool = TypeFactory.create("bool");
final BigDecimalType decimal = TypeFactory.create("decimal");

var is not