Apr 7, 2014 at 1:21 AM
Edited Apr 7, 2014 at 1:21 AM
Something similar has been
. I agree that a constant version of
would be very useful. Not sure if you meant at the local or the class level, or both, but I'd like to see it supported in both.
The problem with the suggested syntax is that ambiguity with parsing
const int = 0;
Should that be valid code? In this case
const int int = 0;
isn't valid either, but what about
const File = 0;
. There potentially could be many perfectly valid names which would be disallowed as constant names, and you'd now have to specify a type in order for that expression
The ambiguity could probably be statically determined in 99% of cases, but I really don't like the fact that adding a using statement could change the parser.
The other thread suggested different syntax that could be supported, right now I'm a fan of using
(for value), so you're examples would be
val i = 0;
val name = "Prabir"
I'm also wondering if the
might be better off as
since the compiler is pretty limited in what it considers to be constant, and it may be frustrating having it as a
. The result is pretty similar in either case.
I'm curious to see what everyone else thinks, but I personally think easy syntax for immutable variables would promote much safer code.