What happened to Module

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 .

Could anyone still shed some more light on that?

2 Likes

They’re working on inline class, and the work has progressed to the point where inline is the answer to many questions.

I think module or module system is also a diffuse concept and not more explanatory. Also, “everything is an object.”

2 Likes

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

But some are more objetive than others.

1 Like

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.

5 Likes

I think the name is perfect for what it actually is: one object.

3 Likes

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.

2 Likes

I also find the current terminology rather unfortunate, because when I say “a is an object”, it is not clear if I mean:

(1) It was declared using the object keyword

(2) It is an instance of AnyRef (aka java.lang.Object) (not primitive)

(3) It is an object as opposed to a type or a method (possibly primitive)

Best, Oliver

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.

3 Likes

martijnhoekstra http://contributors.scala-lang.org/u/martijnhoekstra
April 8

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

As for the history question about why it was changed, on Gitter, at https://gitter.im/scala/contributors?at=5ac8a6dc270d7d3708a0ed5a Martin wrote:

As far as I recall it was felt that object more inline with class than module .

Note that it was already object in Scala 2.7, circa 2008, which is far as back as my own memories go.

I gotta say, I never get tired of your humour

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.

1 Like

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