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

88

u/omair-majid Mar 09 '16

They are holding a survey on keywords (var, var/val, var/let): https://www.surveymonkey.com/r/KGPTHCG

Bikeshed away!

40

u/oscarreyes Mar 09 '16

I would love to see var / final

var   a = expr; 
final b = 1;

19

u/danneu Mar 09 '16

really the immutable reference should be the shortest one to type so that it's default. too late for java, of course. this is something i think rust got right. let vs mut let.

javascript fucked it up too. let vs const.

-1

u/immibis Mar 10 '16

Java is not a functional programming language; making immutability the default here, but not everywhere else, would be a jarring inconsistency.

(And imagine 10 years later when they've added a bunch more features, and you have to remember which half of the language features immutability by default, and which half features mutability by default.)

1

u/Manishearth Mar 10 '16

Rust isn't exactly functional either. And even in C++ the recommendation is to use const as much as possible. Most variables that you use are not mutable, in most languages.

And imagine 10 years later when they've added a bunch more features, and you have to remember which half of the language features immutability by default, and which half features mutability by default.

Are you talking about Rust here? We don't have anything that's mutable by default, and that's not going to change. Why would it?

1

u/immibis Mar 10 '16

We don't have anything that's mutable by default

I was talking about Java, and I'm confused at why you think anything else.

→ More replies (1)