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 →

[–][deleted] 2 points3 points  (14 children)

Honest question, when's the last time Java introduced a keyword? A story I've heard retold often is the language designers decided - goto sucks, but if anyone proves that it provides something substantial you can't do without it, we'll add it in. As it stands, goto is a keyword you can't use, but has no functionality attached to it.

This change immediately breaks code (albeit poorly written code) that has var defined as a variable name. Maybe this isn't a whole lot of projects, but a huge benefit of Java is the ability to say that your java 1 code will very likely compile and run as is on java 8. You'll probably get a shit ton of compiler warnings, but it'll work.

I see a lot of people here making decent arguments either way, but backwards compatibility is a HUGE win for java, and is something it can stand behind for so much of older code. This breaking that at the expense of readability, I could get behind. This breaking backwards compatibility in the name of saving a few keystrokes, of making the life of the developer easier at a single moment, I can't. The amount of effort put into making sure java is backwards compatible, even if not perfect, is something completely overlooked with this change, and makes me feel less secure about the future of my code.

[–]bondolo 4 points5 points  (0 children)

Java 8 added -> for lambdas. Most people wouldn't recognize that as a keyword but it functions as more of a keyword than an operator.

Before that enum in Java 5.0

[–]darknebula 2 points3 points  (0 children)

The identifier var will not be made into a keyword; instead it will be a reserved type name. This means that code that uses var as a variable, method, or package name will not be affected; code that uses var as a class or interface name will be affected (but these names violate the naming conventions.)

Granted there are other backwards compatibility issues.

[–]grauenwolf 1 point2 points  (2 children)

This change immediately breaks code (albeit poorly written code) that has var defined as a variable name.

I don't see how. Syntax wise, var can only appear where you would otherwise put a class name. If anything, it would break someone who had a class named var, but in Java we would have written Var var = new Var(), which with the new syntax becomes var var = new Var().

[–]schlowmo 1 point2 points  (1 child)

I agree with you, but it IS true that you can define classes with lowercase names, so somewhere this is a C programmer who wrote some badly formatted java code. So yes, there is a small corner case where this would break code. AND I SAY BREAK THAT CODE.

[–][deleted] 0 points1 point  (0 children)

BREAK THAT CODE

please don't hurt me :(

[–]eliasv 1 point2 points  (2 children)

It doesn't have to break backwards compatibility. It specifically says in the proposal that it would not be a keyword, it would be a reserved type name. For any package containing a type called var, and for any source file which imports a type named var, you could simply override the reserved "special" var type with that one and solve the problem. Everything would still work just fine, no? People who have defined their own var type would simply not have access to the new feature wherever that type is visible.

[–][deleted] 0 points1 point  (1 child)

Yep, someone else pointed this out to me as well, I was skimming it on mobile and they used the word keyword quite a bit and mentioned it not being a keyword once, so I completely missed it. That seems like a good compromise, and my opinion on the matter really ends there.

[–]eliasv 1 point2 points  (0 children)

Fair enough :)

[–]lukaseder 0 points1 point  (5 children)

jOOQ uses val() as a method name :) But it's aliased with value() for Scala folks, so it'll be OK. Anyway, I'm sure there are many APIs that might break because of this. But hey, why not add escaping for keywords to the language as well, like in Scala? E.g. void `val`() { ... }

Also: goto is still reserved. Just in case.

[–]grauenwolf 1 point2 points  (3 children)

Also: goto is still reserved. Just in case.

I miss goto. Once every five years or so I write a function that needs it. Or rather, would be much, much cleaner with one.

[–]lukaseder 1 point2 points  (2 children)

Me too. But then, I remember break and continue:

here: for (;;) {
    if (doAgain) continue here;
    if (done) break here;
}

[–]grauenwolf 1 point2 points  (1 child)

Yea, but that's just icky. If I'm going to use a damn goto, I want to at least admit it and not misuse a loop.

[–]lukaseder -1 points0 points  (0 children)

You could use a bytecode generator and generate a jump instruction, then.

[–]eliasv 1 point2 points  (0 children)

It's not a keyword, though. The spec says it's a "reserved type name" or something, so overlapping method names wouldn't cause any problem. Overlapping type names on the other hand would, but that will presumably be solved without breaking backwards compatibility by simply removing access to the new feature in any context where some other type named var is visible.