MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/49prtn/var_keyword_proposed_for_java/d0udkj2
r/programming • u/adila01 • Mar 09 '16
395 comments sorted by
View all comments
Show parent comments
8
Why not var for mutable things, and Val for immutable things?
0 u/[deleted] Mar 10 '16 [deleted] 6 u/demon_ix Mar 10 '16 var/val are already used in this way in other languages (scala, kotlin and more). They also have the benefit of being the same length, which is nice. 6 u/mirhagk Mar 10 '16 As much as I'm voting for var/val in C# I do think Java would benefit from just doing final since everyone already knows that keyword and what it means in Java. 3 u/ComradeGibbon Mar 10 '16 That's pretty nice actually. val/Val/value is immutable. var is mutable.value quarter_pi = 3.14/4.0; var foo = bar->baz->foo; foo += quarter_pi; 0 u/Alphasite Mar 10 '16 Because var and val as visually very similar. Its harder to skim than needs be. 1 u/Daenyth Mar 10 '16 That's not my experience when using Scala, and syntax highlighters don't need to make them the same 2 u/Alphasite Mar 10 '16 Maybe, but it's an unnecessary similarity. 0 u/[deleted] Mar 10 '16 [deleted] 1 u/Alphasite Mar 10 '16 var/let doesn't produce any extra boilerplate, it just makes the immutable case a little more obvious.Frankly, it's using kotlin and swift hat has me convinced that Swift's var/let is the better choice.If they also decide to go down the Rust route and allow you to shadow other let declarations then let is an even better fit.
0
[deleted]
6 u/demon_ix Mar 10 '16 var/val are already used in this way in other languages (scala, kotlin and more). They also have the benefit of being the same length, which is nice. 6 u/mirhagk Mar 10 '16 As much as I'm voting for var/val in C# I do think Java would benefit from just doing final since everyone already knows that keyword and what it means in Java.
6
var/val are already used in this way in other languages (scala, kotlin and more). They also have the benefit of being the same length, which is nice.
6 u/mirhagk Mar 10 '16 As much as I'm voting for var/val in C# I do think Java would benefit from just doing final since everyone already knows that keyword and what it means in Java.
As much as I'm voting for var/val in C# I do think Java would benefit from just doing final since everyone already knows that keyword and what it means in Java.
var
val
final
3
That's pretty nice actually. val/Val/value is immutable. var is mutable.
value quarter_pi = 3.14/4.0; var foo = bar->baz->foo; foo += quarter_pi;
Because var and val as visually very similar. Its harder to skim than needs be.
1 u/Daenyth Mar 10 '16 That's not my experience when using Scala, and syntax highlighters don't need to make them the same 2 u/Alphasite Mar 10 '16 Maybe, but it's an unnecessary similarity. 0 u/[deleted] Mar 10 '16 [deleted] 1 u/Alphasite Mar 10 '16 var/let doesn't produce any extra boilerplate, it just makes the immutable case a little more obvious.Frankly, it's using kotlin and swift hat has me convinced that Swift's var/let is the better choice.If they also decide to go down the Rust route and allow you to shadow other let declarations then let is an even better fit.
1
That's not my experience when using Scala, and syntax highlighters don't need to make them the same
2 u/Alphasite Mar 10 '16 Maybe, but it's an unnecessary similarity. 0 u/[deleted] Mar 10 '16 [deleted] 1 u/Alphasite Mar 10 '16 var/let doesn't produce any extra boilerplate, it just makes the immutable case a little more obvious.Frankly, it's using kotlin and swift hat has me convinced that Swift's var/let is the better choice.If they also decide to go down the Rust route and allow you to shadow other let declarations then let is an even better fit.
2
Maybe, but it's an unnecessary similarity.
0 u/[deleted] Mar 10 '16 [deleted] 1 u/Alphasite Mar 10 '16 var/let doesn't produce any extra boilerplate, it just makes the immutable case a little more obvious.Frankly, it's using kotlin and swift hat has me convinced that Swift's var/let is the better choice.If they also decide to go down the Rust route and allow you to shadow other let declarations then let is an even better fit.
1 u/Alphasite Mar 10 '16 var/let doesn't produce any extra boilerplate, it just makes the immutable case a little more obvious.Frankly, it's using kotlin and swift hat has me convinced that Swift's var/let is the better choice.If they also decide to go down the Rust route and allow you to shadow other let declarations then let is an even better fit.
var/let doesn't produce any extra boilerplate, it just makes the immutable case a little more obvious.
Frankly, it's using kotlin and swift hat has me convinced that Swift's var/let is the better choice.
If they also decide to go down the Rust route and allow you to shadow other let declarations then let is an even better fit.
8
u/Jacoby6000 Mar 10 '16
Why not var for mutable things, and Val for immutable things?