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".

5

u/Xenasis Mar 10 '16

This isn't changing Java to be untyped or weakly typed at all. This won't change how Java's type system works whatsoever.

I'm a massive fan of strongly typed languages like OCaml, Agda and Haskell, and not a single one of them requires you to declare what type your data is. Requiring information that the compiler can figure out by itself does not make a language any weaker typed and does not change the type system. I'm under no delusion that Java's using Hindley-Milner, but it's worth pointing out nonetheless.

The difficulty of debugging languages like JavaScript or Python isn't helped by the type system, you're right, though this isn't turning it into that at all. Java will keep the type system it has now and won't be any less clear unless the code wasn't clear to begin with.

1

u/evil_burrito Mar 10 '16

Sure it will. When you, as a human, are stepping through the source code, there will be an extra step to figure out the type of a particular variable.

As a human who has to read other people's code, this would bother me, so I don't like it. We don't have to agree.

1

u/[deleted] Mar 10 '16

[removed] — view removed comment

1

u/evil_burrito Mar 10 '16

I like that Java encourages the use of interfaces. Maybe this difference in preference between us is related to the source of our disagreement.

1

u/[deleted] Mar 10 '16

[removed] — view removed comment

1

u/evil_burrito Mar 10 '16

I agree that if one doesn't get the purpose of interfaces, Java is going to be a lot of fun for anyone.

Interestingly, since I'm not a C# guy, don't work on Windows, and don't have the Microsoft Family of Products ready and willing to display System.Data in all its interactive finery, I would have to just download the source of System.Data to look at it. And I would probably look at it in Emacs. I hope there isn't a lot of stuff defined with "var" in there.

1

u/[deleted] Mar 10 '16

[removed] — view removed comment

1

u/evil_burrito Mar 10 '16

Perhaps they have internal coding standards about using var. I know that I'm a lot more lax in terms of structure, encapsulation, all that, when writing tests.