modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.07k stars 2.59k forks source link

[Docs] The term "initializer" is erroneously used in place of "constructor" #2391

Open nmsmith opened 5 months ago

nmsmith commented 5 months ago

Where is the problem?

https://docs.modular.com/search?q=initializer

What can we do better?

In various places in the Mojo manual and the API documentation, the __init__ method is referred to as an "initializer". The official term in the Python community is "constructor", as can be concluded by searching for "constructor" vs. "initializer" in the official Python documentation.

It so happens that a minority of Python users refer to __init__ as an "initializer", because:

But as stated, the use of the term "initializer" is less common, and has not been adopted by the official Python documentation. Furthermore, very few programming languages use this term. Accordingly, to be consistent with Python, I think Mojo should stick to "constructor".

There are at least two pages in the manual (one, two) where the word "initializer" is used instead of "constructor", and there are 10+ docstrings in the standard library that make the same mistake.

If desired, I can make a pull request to resolve this issue.

Anything else?

No response

YichengDWu commented 2 months ago

I oppose this idea.

The official term in the Python community is "constructor"

That's because Python adopted jargon from other languages. initializer is what __init__ really is and experienced python users know this.

__new__ is the actual "constructor" since it returns an instance.

__init__ is an "initializer" since it gets self as the first argument, therefore the object already exists. And it doesn't return anything.

nmsmith commented 2 months ago

Mojo doesn't really have the freedom to coin a new name for an established Python concept. I suspect the only option here is to look at the facts—i.e. what is the official term for Python's __init__ method as stated or implied by the official documentation—and ensure Mojo is consistent with those facts.

YichengDWu commented 2 months ago

what is the official term for Python's init method as stated or implied by the official documentation

Please point me to the official docs where it says __init__ is the "constructor".