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

16

u/stepancheg Mar 09 '16 edited Mar 09 '16

Seems like you are mixing weakly/strongly typed languages and dynamically/statically typed.

Anyway, with var Java is still statically and strongly typed.

Strong means "17" is String, and cannot be viewed as int.

Static means that even without explicit type each var still has a type, and you CANNOT write:

var i = 19;
i = "there";

3

u/evil_burrito Mar 10 '16

No, I'm not. My complaint isn't that it makes Java a weakly-typed language. My complaint is that it makes Java read like a weakly-typed language, which makes code other people wrote harder to understand.

0

u/[deleted] Mar 10 '16

[deleted]

0

u/evil_burrito Mar 10 '16

That's a Visual Studio thing or something similar? I don't work on Windows.

Regardless, I'm talking about the ability to quickly grok unfamiliar code. I believe that having type information that isn't obvious at a glance would be a detriment to me. Thus, I don't like this proposal.

0

u/NimChimspky Mar 10 '16

intellisense isn't windows specific. its a feature of ides, in most languages, including java.

Type information is there, and its readable, just slightly different and more concise.

3

u/evil_burrito Mar 10 '16

OK, I wasn't familiar with the term. I guess it covers things like hovering/clicking/what-have-you to get more information about the statements you're looking at.

This is fine and good, and I love my IDE. I've used most of them over the years, but have converged on Eclipse.

As I said in another reply, though, I don't always look at code, especially strange code, in an IDE. If I want to go through the source of an included library, I rarely take the time to set it up in a complete project that compiles, etc.

If I haven't automatically downloaded the source JAR via Maven, then I'll download the source, or check it out from svn/git and read through it with Emacs. It's possible to set all that bidness up with Emacs (Intellisensetm) I suppose, but, for this purpose, I don't go through the effort to do so. Now, I'm stuck when reading something like:

var thisThing = new MyDerivedClassButYouDontKnowTheSuperclass<>();

instead of

List<Something> thisThing = new MyDerivedClassButYouDontKnowTheSuperclass<>();

That's my discomfort with this proposed change. I guess it's tied into the fact that I don't agree with the premise of the change, that Java requires too much boilerplate code. I think verbosity and legibility generally correlate. I think that brevity and legibility are generally in opposition.

5

u/skocznymroczny Mar 10 '16

intellisense is a Microsoft name for that, I don't know if they have any rights to the name, but anyway, the generic term is "code completion" or "code assistance" I guess.

3

u/NimChimspky Mar 10 '16

Whatever you call it, it's not specific to Microsoft products -which was the point.

2

u/[deleted] Mar 10 '16

^

This is what I meant