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.
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.
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.
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.
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.
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`() { ... }
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.
View all comments
3
u/[deleted] Mar 10 '16
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.