__init__ is the initialiser

Ethan Furman ethan at stoneleaf.us
Fri Jan 31 22:30:46 EST 2014


On 01/31/2014 07:16 PM, Terry Reedy wrote:
> On 1/31/2014 7:13 PM, Ethan Furman wrote:
>> On 01/31/2014 03:43 PM, Ned Batchelder wrote:
>>> On 1/31/14 6:05 PM, Ben Finney wrote:
>>>> Ned Batchelder writes:
>>>
>>> I'm not hoping to change any official terminology. I just think that
>>> calling __init__ anything other than a constructor
>>> is confusing pedantry.  It is a constructor, and Python constructors
>>> work differently than those in C++ and Java.
>>
>> And I would say the opposite.  __init__ is not creating anything,
>
> As you pointed out in a different response, Python has one default, two-phase constructor. type.__call__. Typically,
> .__new__ allocates a generic object (with one customization as to class). .__init__ creates, from that mostly generic
> object, a customized instance of class C with the minimal attributes needed to be an instance of C, with value specific
> to the instance.
>
> Creating a painting on canvas has two similar phases. Prepare a generic blank canvas stretched on a frame and coated
> with a white undercoat. Paint a particular picture. Would you say that the second step is not creating anything?

Very nicely put.  Considering the discussion that this topic has engendered, you will hopefully agree that the current 
docs could use a little improvement.  :)

--
~Ethan~



More information about the Python-list mailing list