One of the oddest things I encountered when starting to learn Scala was seeing variables called values instead of variables.
When I first started reading the docs I saw a list of values of the classes, traits etc. I kept wondering WTF is a value why not call it a variable like every other language.
So for a while I just thought the Scala community just referred to all class variables as values.
Then I was reading the docs some more, I found this page. It has this one easy to miss line that answers the question why are vals called values instead of variables.
The second sentence below the difference between Val and Var
valfields can’t vary, some people refer to them as values rather than variables.”
And that is the answer. In the Scala API documentation most classes/objects you see has a list of values defined with val.
I suppose the class variables are defined this way so that you don’t accidentally mutate them or change them.
I am still not sure why methods are called members yet, when I figure that out maybe I’ll write about it.
You must log in to post a comment.