I do not know much about OO-languages, but from what I have seen, it seems most class-based OO-languages uses a keyword new
(or something equivalent) to create an object. Prototype-based OO-languages like JavaScript even fake it.
From a viewpoint of keeping the syntax simple, why not leave out the new
keyword and use only the constructor (typically of the same name as the class)?
Is there any semantic consideration involved in prefixing the constructor with a new
keyword?
I have noticed that in Scala, if you define a case
-class, you can simply use the constructor without a preceding new
to create an object, while for other classes, you have to use new
. I do not know the reason. I mention it simply because it may be related.
List()
is it creating a list, or is it listing something (noun or verb)? If I writenew List()
the ambiguity goes away.this
, couldn't you? I think "new distinguishes object creation from method invocation" is exactly the point, though... not necessarily just for the compiler/interpreter, but also for the developer.