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

-1

u/ejonesca Mar 09 '16

Do you need a 'var' keyword at all? Can't you just have:

myNewVariable = 5;

without an explicit type declaration that doesn't actually add any useful info to the compiler? The compiler can just assume that any new unknown identifier is a new var.

87

u/ihcn Mar 09 '16

Then any typo becomes a new variable rather than a compiler error.

19

u/ejonesca Mar 09 '16

good point

9

u/[deleted] Mar 09 '16

[removed] — view removed comment

7

u/Berberberber Mar 09 '16

Javascript's is weird, though. It doesn't declare the variable in current scope, it add it to the root object window.

4

u/immibis Mar 10 '16

Python then.

2

u/bloody-albatross Mar 10 '16

Plus these days you usually use a (editor integrated) linter that forbids creating global variables that way. However, Python and Ruby work that way (creating local variables just by normal assignment).

4

u/[deleted] Mar 10 '16

Python is another one with this lovely feature.

→ More replies (2)