Hacker News new | past | comments | ask | show | jobs | submit login

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.



I 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.


if it is not constant, it must be variable i.e. changing. Mutation = change.


def 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.


No. A variable in mathematics does not change (mutate). And yet it is not a constant.

You’re thinking inside the imperative programming box.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: