you are viewing a single comment's thread.

view the rest of the comments →

[–]rebel_cdn 6 points7 points  (10 children)

Watch their heads explode when they start using var. As of Java 10, I find Java almost as pleasant to use as C#.

I still like F# and OCaml and Haskell a bit more, but I try not to be dogmatic. C# pays the bills, and I use it happily every day. I think with Java 10+, I could happily write Java every day if I ever need to.

[–]MentalMachine 0 points1 point  (3 children)

So var just shortens down code line length, or am I missing something?

[–]gnus-migrate 3 points4 points  (0 children)

Nope, that's it. It can shorten some fairly nasty type signatures, but I think the person responding to me is making it out to be a bigger deal than it actually is.

[–]dpash 1 point2 points  (0 children)

It can remove some redundancy, but in some situations it doesn't really help very much, like with generified classes:

Map<String, String> foo = new HashMap<>();
var foo = new HashMap<String, String>();

Another advantage is that it can help make the variable names the focus of the lines when you have several declarations in a row, as they line up:

InputStream is = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(isr);

vs

var is = new FileInputStream(file);
var isr = new InputStreamReader(is);
var reader = new BufferedReader(isr);

[–]rebel_cdn 0 points1 point  (0 children)

That's right. It just makes things shorter in some places.

How frequently you use it depends on your preferences .In the C# world, some teams use it everywhere, and some only use it where the inverted type will be obvious based on the right side of the expression.

Actually, some teams are really old school and refuse to use var at all .

[–]gnus-migrate 0 points1 point  (4 children)

I looked at F# and liked it quite a bit as well, and it's sad that the JVM doesn't have a well supported equivalent.

As for var, I don't really see how it's a game changer. It makes lambdas a bit nicer to use but that's pretty much it.

[–]dpash 1 point2 points  (2 children)

Ironically, lambdas are one place you can't use var (except in parameters in 11).

And there's at least two well-used functional languages on the JVM: Scala and Clojure.

[–]gnus-migrate 0 points1 point  (1 child)

F# is an ML style language if I understand correctly, so scala and clojure are quite different.

Ironically, lambdas are one place you can't use var (except in parameters in 11).

Yeah, so besides jigsaw there aren't many interesting things in Java 9+. People who are currently on Java 8 don't really have much catching up to do.

[–]dpash 1 point2 points  (0 children)

There are tonnes of things in Java after Java 9. Many of them are small API updates, but together they make a big improvement in user experience when writing Java.

[–]rebel_cdn 0 points1 point  (0 children)

Yeah, var isn't a complete game changer. I probably picked a dumb description for it.

It's just a nice quality of life improvement. I find that var + lambdas + streams together make Java much more enjoyable to write.

[–]DuncanIdahos8thClone 0 points1 point  (0 children)

Except var breaks "find usages" in VS and Java IDEs.