r/programming • • Mar 09 '16

var keyword proposed for Java

http://openjdk.java.net/jeps/286
250 Upvotes

395 comments sorted by

View all comments

Show parent comments

7

u/orclev Mar 10 '16

That's why I voted for var/let, I like that they're easier to tell apart. I feel like var/val would be just a bit too easy to typo.

1

u/kqr Mar 10 '16

Of all the concerns there, typos gotta be the smallest. A val being typoed as var will work just like you intended it to. A var typoed as val will at worst trigger a compiler error. It's really innocuous.

3

u/orclev Mar 10 '16

Except that isn't the case, a val typoed as a var becomes mutable, and might lead to bugs if it's changed unexpectedly. The opposite would likely lead to a compiler error (or else just safer code since not erroring would indicate you should have used a val in the first place).

1

u/kqr Mar 10 '16

That requires more than a typo though -- that requires you to treat a variable you think is immutable as if it was mutable.

2

u/orclev Mar 10 '16

True, but who says it's you that treats it like that? Or that you remember 6 months down the line that you intended that variable to be immutable originally and wrote part of the code based on that assumption?

1

u/tehoreoz Mar 11 '16

increasing opportunity for mistakes is no good. maybe on an individual level you never see the impact, but what if your product is being used by millions of people? flaws like this start to become problems that people complain about every day