__init__ not a "constructor" ?
tim at vegeta.ath.cx
Tue Aug 14 02:11:56 CEST 2001
Me parece que Kirby Urner <urner at alumni.princeton.edu> dijo:
> I notice the author of the Dive Into Python tutorial cautions
> that __init__ is not trully a class constructor, as by the time
> it's invoked, an instance already exists (hence the argument
> 'self', hence the fact that classes don't need an __init__
I'm not sure what the author means, but:
def __init__(self, *args):
# do stuff
... is roughly analogous to C++'s constructors, if you don't count C++'s
implicit passing of the object.
...both of which are drastically different from Perl's OO constructor
syntax, requiring a constuctor of any name to "bless" this object (a
string ref, an array ref, a hash ref, a filehandle ref) into the given
"class" (ie, package name). This is no doubt convoluted, but simplifies
certain processes, such as a wrapper object for an array;
$obj-> then refers directly to the first element, rather than having
to call, say, $obj->return_element(0). OTOH, doing this in Python
requires a lot of extra __*__ methods in the class. You can see there
are dozens of arguments this way, but I much prefer OO in Python. <wink>
> I'm wondering if it's therefore considered faux pax to refer to
> the constructor of a Python user-defined class, meaning __init__,
> or if there's some tacit liberalizing of "constructor" (it's meaning)
> going on, such that this usage is acceptable.
For as much as OO is talked about, there are sooooooo many different
words for the same thing.
object == instance
data member == attribute ( ~ instance variable )
inheritance == derivation
interface == behavior
interface (Java) == 'mix-in' class
method call == message
instantiation == creation
super class == base class
* and many, many more *
As such, words are bound to have their meanings confused; but I don't
think people ever agreed on terminology in the first place. <wink>
IMNERHO, the purpose of OO is abstraction of data to make it
easier to use and extend. If you're accomplishing this, it's OO.
IMNERHO = In My Never Even Remotely Humble Opinion
<dons flame-proof armor> <wink!>
Usenet is essentially a HUGE group of
people passing notes in class.
-- R. Kadel
More information about the Python-list