--
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 scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
There also really isn't any reason they shouldn't be allowed to be lazy vals as well. Look atfor an example of this sort of thing. I don't think anyone can argue that
With regards to the original question, I don't think `var` parameters for methods are a likely addition to the language. Scala left behind one or two of the imperative-oriented features of Java to keep the language a little smaller -- for example we don't have pre-/post-increment.
On Monday, September 9, 2013 5:15:10 AM UTC+8, Jason Zaugg wrote:
With regards to the original question, I don't think `var` parameters for methods are a likely addition to the language. Scala left behind one or two of the imperative-oriented features of Java to keep the language a little smaller -- for example we don't have pre-/post-increment.If I am not mistaken, `var` parameters are the default for non-case class constructors. This is another example of lack of regularity in the language. Such inconsistencies cause bewilderment for the programmer. And we saved how many lines in the grammar and in the compiler to make it non-regular for how many targeted millions of programmers (hopefully)?
--
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 scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
On Monday, September 9, 2013 5:15:10 AM UTC+8, Jason Zaugg wrote:With regards to the original question, I don't think `var` parameters for methods are a likely addition to the language. Scala left behind one or two of the imperative-oriented features of Java to keep the language a little smaller -- for example we don't have pre-/post-increment.If I am not mistaken, `var` parameters are the default for non-case class constructors. This is another example of lack of regularity in the language. Such inconsistencies cause bewilderment for the programmer. And we saved how many lines in the grammar and in the compiler to make it non-regular for how many targeted millions of programmers (hopefully)?
Also I don't agree it is an imperative feature, but that is a deeper discussion:
http://stackoverflow.com/questions/602444/what-is-functional-declarative-and-imperative-programming/15382180#15382180
"The declarative property is where there can exist only one possible set of statements that can express each specific modular semantic.The imperative property is the dual, where semantics are inconsistent under composition and/or can be expressed with variations of sets of statements."
--
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 scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
No need to trot out the CV, your arguments will do fine on their own.
Scala deliberately unifies ADTs and class hierarchies.You can write operations that pattern match over the operations, or you can add methods to the classes in the hierarchy.
You can leave them as immutable, or encapsulate mutable state within them in a normal OO way. They are not really supposed to be two different things; it is really just two different styles of using the same thing.
Allowing mutable state within a class is a feature; you can do things with the class that you wouldn't otherwise be able to do. (Whether you should is another matter, of course :-)
Allowing a mutable var as a method parameter doesn't unlock any capabilities in the language; it gives you a meaningless choice that buys you nothing, where one option is clearly superior to the other in almost any conceivable situation.
I just don't see any logic about why you mention the Expression Problem.
An ADT should be time-invariant and OO approaches state management on a different semantic level, so why conflate the two concepts?
I don't see where you have made any cogent argument against my point, which is that for an ADT the class should be immutable according to the theory. If you want to deviate from that, it is a feature. Okay fine. But my point is that for the general OO semantics, there is no such applicable theory, and thus the constructor parameters should be `var` by default and so as to provide a clear boundary between the concepts of a class.
Allowing a mutable `var` as a regular OO class constructor parameter does unlock capabilities (that are default in Java, C++). So if those were the default, then I would wonder why methods can't be `var` especially when even ADTs are allowed to be `var`.
Okay you are saying that for classes there are significant capabilities unlocked for mutable fields, but there are also capabilities unlocked by making a method parameter re-assignable (it doesn't make anything mutable from the outside as class fields do). So I understand now making method (function) parameters re-assignable by default, because it prevents a silly human error, so we force the user to declare them var to make sure that is their intent. But why force the noise of another identifier by not allowing `var` in the parameter list? I end up prepending underscores on the method parameter which is needless noise.
--
Sorry if I was unclear - the point is simply that Scala is designed to unify the two concepts (ADTs/Pattern-matching vs Classes/dynamic dispatch), rather than having separate features and making you choose. You can mix and match between them.
Your point that "ADTs are ADTs and classes are classes, and never the twain shall meet" might or might not be a good one, but that is not how the language has been designed.
The effects of a "var" method parameter are invisible outside of the method. Although they are allowed in C++ and Java, style guides for these languages often forbid directly reassigning arguments because of the potential for confusion and error.
It is never required; code can always avoid it with minor adjustments.
Var as a constructor parameter gives you mutable state in your object, which lets you model identity and change over time in an efficient, but complex, way. It is useful at times, and occasionally indispensable.
The two cases here are wildly different in their utility as language features. There's no reason to think that because you provide the useful one, you should also provide the useless one for consistency.
import scala.math.Ordering.Implicits._def bounded[T:Ordering](lower:T, upper:T)(value:T) = lower max value min upperdef someDef(input:Int = bounded(0,10)(value)) = input something or other
+1