Automatic val declaration

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic val declaration

reynaldo.gil
Can the language be modified so that all new variables in the left side of an assignment be considered a val declaration. For example:
"a=3" be the same than "val a=3". I'm boring  due to type so many "val". I think is is bureaucratic and the compiler can infer that. Also in this way the language enforce the use of val over var. What do you think in wrong in that? Thanks Gil

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Automatic val declaration

Naftoli Gugenheim
object Main {
  var spelling = 10

  def inc() {
    speling = spelling + 1
  }

  for(i <- 1 to 10) inc()

  println(spelling)
}


On Thu, Sep 18, 2014 at 1:40 AM, <[hidden email]> wrote:
Can the language be modified so that all new variables in the left side of an assignment be considered a val declaration. For example:
"a=3" be the same than "val a=3". I'm boring  due to type so many "val". I think is is bureaucratic and the compiler can infer that. Also in this way the language enforce the use of val over var. What do you think in wrong in that? Thanks Gil

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Automatic val declaration

Simon Ochsenreither-3
In reply to this post by reynaldo.gil
No, it's not possible. Have a look at languages who thought it was a good idea, like CoffeeScript: It has been a disaster.

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.