"self" in a class is annoying and errorprone

eichin at metacarta.com eichin at metacarta.com
Thu Feb 13 22:07:45 CET 2003

> Python is not for everyone.  Perl and Ruby are also very good.  Perl
> and Ruby do not force you to use a variable like 'self'.

Not to confuse the issue, but in methods, perl *does* require a self;
the object itself is the first argument in any method call, and
referencing into it is the way you get at members; there are, of
course, far too many ways to do this, but something like

sub consider {
    my $self = shift;
    my $port = $self->{nextport};

is one of the more common and readable forms (in particular, it's the
form you'll find in examples and documentation.)  You could call it
something else, or even use $_[0] directly, but that's the only way
you're going to actually find the object members...

More information about the Python-list mailing list