0

Hi,

may anybody tell me why there is a init AND a new-method? Why not using one constructor-method like we have to use in java and other OO-lanuages?? Would be nice if somebody can give me an idea about that. Thanks a lot

Jonny

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by sneek
1

I think it maintains the traditional distinction between allocation and initialization. When you use structures in C for example, you must first use malloc to allocate a structure and then you initialize the structure's content. These are 2 different kinds of operations. For example you can decide to change your allocation strategy (implementing a garbage collector or a memory pool or whatever) an this doesn't interfere with the fields intitialization. In C++, you can override the new operator for such things. Other OO languages like objective C separate allocation and initialization. So, in python, __new__ is for allocation and __init__ for initialization.
You could say that allocation deals with memory and initialization deals with your program's logic.

Edited by Gribouillis: n/a

0

Oh okay. I did not know that other languages do so either, but you example with the c-structures sounds good. Thank you :)

Jonny

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.