By this logic many languages would have no "constructors" even though people have used this term for decades. C++/Java, for example. This article could use a better and less clickbaity title.
Hi, I'm Swastik Baranwal, a software developer from New Delhi, India passionate about open-source contribution, Gopher, Pythoneer, Compiler Design and DevOps.
Exactly. Coming from C++ I'd say the function that initializes new objects is the constructor (this term is also used by the ISO specification). What this article is saying is that the Python equivalence of allocator in C++, or the implicit object factory in Java, is the "true" constructor. I mean yeah perhaps it suits the English definition of the verb "construct" better, but people have used the term "constructor" to call the "initializer" function for decades. Also both programming and computer science are full of inappropriate jargons, so why wasting time saying this yet another jargon is imprecise?
Hi, I'm Swastik Baranwal, a software developer from New Delhi, India passionate about open-source contribution, Gopher, Pythoneer, Compiler Design and DevOps.
After reading all the arguments. I have edited the post a bit so that it does not looks misleading. If there's anything still unclear then please tell.
take a look at C++ as an example. once you are in a constructor the classes memory has already been allocated, even uninitialised members have memory assigned to them. The constructor is customising the instance.
A c++ class with a zero constructor is like a python class with no init. you get a default instance.
Hi, I'm Swastik Baranwal, a software developer from New Delhi, India passionate about open-source contribution, Gopher, Pythoneer, Compiler Design and DevOps.
I thought you changed the title, it definitely wasn't what I remembered seeing.
I think it would be useful to understand exactly what internal functions are called every time a new instance is created, for instance __new__ and __init__, are there any others?
Hi, I'm Swastik Baranwal, a software developer from New Delhi, India passionate about open-source contribution, Gopher, Pythoneer, Compiler Design and DevOps.
By this logic many languages would have no "constructors" even though people have used this term for decades. C++/Java, for example. This article could use a better and less clickbaity title.
Can you define constructor
Exactly. Coming from C++ I'd say the function that initializes new objects is the constructor (this term is also used by the ISO specification). What this article is saying is that the Python equivalence of allocator in C++, or the implicit object factory in Java, is the "true" constructor. I mean yeah perhaps it suits the English definition of the verb "construct" better, but people have used the term "constructor" to call the "initializer" function for decades. Also both programming and computer science are full of inappropriate jargons, so why wasting time saying this yet another jargon is imprecise?
yep. It worries me that this article is going to mislead and confuse people learning the language.
After reading all the arguments. I have edited the post a bit so that it does not looks misleading. If there's anything still unclear then please tell.
what do you define as a "true" constructor?
take a look at C++ as an example. once you are in a constructor the classes memory has already been allocated, even uninitialised members have memory assigned to them. The constructor is customising the instance.
A c++ class with a zero constructor is like a python class with no init. you get a default instance.
I changed the title again. Does it looks fine now?
I thought you changed the title, it definitely wasn't what I remembered seeing.
I think it would be useful to understand exactly what internal functions are called every time a new instance is created, for instance
__new__
and__init__
, are there any others?There is also
__del__
which is called but it is not needed to make because it de-allocates the object. I think it functions like a destructor.