I find that object can be confusing to newcomers to the language, especially when explaining something: In the minds of newcomers, objects tend to be instances of classes - roughly what we would call values in scala. It can get confusing when one is talking about a scala object and the other thinks they are talking about some value that they call an object because that’s what they’re used to calling those things. I usually explain that they should think of an object like a module, and not like what they think of as an object.
When asking around why it’s called object rather than for example module, I learned that in Ye Olde Scaela it actually was called that, but that has since been replaced with object.
While the ship on renaming the thing has probably sailed by now, it did make me wonder why it was changed in the first place. Does anyone still know what the rational for that was at the time? On scala/contributors Martin mentioned
As far as I recall it was felt that object more inline with class than module .
I agree that in my opinion both object and module could cause the same level of confusion to newcomers. I don’t remember what I personally thought about it as a person new to Scala, but I can confirm that my friend who is pretty new to the language often confuses Scala’s object with other ideas, as @martijnhoekstra wrote.
When thinking of modules the first thing that comes to my mind is something like modules in an IntelliJ project
Other than as modules, object is very often used within ADTs. Although, I suppose that even here, object isn’t particularly self-explanatory. However, I’d say that module would be even less so.
In this usage, it almost seems like singleton would be the dual to class. Or something else signifying unity.
object is also used for companion objects, which I guess are like modules, but are really more like holders of class methods.
In conclusion, given how generic the construct is, it’s kind of difficult to give it just the right name. I think object is almost perfect in its vagueness, but without being too jargony.
At this point I regret expressing my mild dissatisfaction for the name object, since what I am really after instead of debating whether it’s the right name is when and why exactly it was changed.
They had to change the keyword from module because of the ambiguity with Maud jewel. That was back when every discussion about “diamond inheritance” was sidetracked that way.
I find that object can be confusing to newcomers to the language,
especially when explaining something: In the minds of newcomers, objects
tend to be instances of classes
But object is an instance, specifically the only instance in the scope
where it’s declared, of the type .type, which has an underlying class
implementation.
roughly what we would call values in scala. It can get confusing when one
is talking about a scala object and the other thinks they are talking
about some value that they call an object because that’s what they’re used
to calling those things.
True. Usually prefixing with “singleton object” or “companion object” (if
actually a companion) can clarify.
I usually explain that they should think of an object like a module, and
not like what they think of as an object.
I’m not sure what a module is, but I know what an object is, it’s an
instance of a class. Objects defined by object can, just like any other
class, implement traits/interfaces. Can a module do that? I don’t know.
yeah… usually. but you still run into terminology trouble when object is nested inside something else, for example
class C { object O }
Here O isn’t a singleton in the usual sense, it’s only a per-instance-of-C “singleton”.
I don’t really have a fix to suggest. In writing you can put backticks around object to emphasize that we’re talking about something where the keyword was used, but speaking out loud, it can get confusing.
(As for the word “module”, I kinda like the associations with modules in ML, but most people don’t have those associations.)
I wasn’t suggesting using the term “singleton” when the scope makes it not so. In fact, I’ve often objected (no pun intended) to calling objects “singletons” as a general rule, because they are often not.
As someone who first got hands into dotty, this was my impression as well as to why it was named object before figuring it was a reminiscent of the past