5 ms·
I don’t understand why Scala chose “var” for mutable variables. A variable is not defined by being mutable—it is defined by being variable, i.e. not a constant
by avgcorrection 5y ago
I don’t understand why Scala chose “var” for mutable variables. A variable is not defined by being mutable—it is defined by being variable, i.e. not a constant. And it is immutable in math (where we don’t have to care about performance). So “val” is also a “var”, conceptually.
- JulianMorrison 5y agoI think it was Fortran which introduced the equivalence between programming variables (that are a mutable piece of memory) and mathematical variables (which describe a relationship). But they aren't really the same. And "variable" has become too fixed in computer science usage to be repaired back to its earlier mathematical meaning.
- bruce343434 5y agoif it is not constant, it must be variable i.e. changing. Mutation = change.
- avgcorrection 5y agoNo. A variable in mathematics does not change (mutate). And yet it is not a constant. You’re thinking inside the imperative programming box.
- ackfoobar 5y agodef plusOne(x: Int) { val y = x + 1; return y } In the line of code above, `y` is an immutable variable. It does not mutate, yet it "varies" as different values of x come in.