Why we will use obj$func() often

Jeff Epler jepler at unpythonic.net
Fri Apr 23 07:30:12 EDT 2004


On Fri, Apr 23, 2004 at 01:24:42AM -0700, Mark Hahn wrote:
> My biggest problem right now is stupid aesthetics.  I have to decide where
> to place Prothon on the continuum between lisp and perl.  When I crossed the
> line and added $ for self people screamed bloody murder that it looked like
> Perl.  Before when I had a period for self they thought it looked great.  I
> can't believe how much they care about something so silly.

I didn't know about your ^ syntax either.

In Python, there is one way[*] to get an attribute on an object.  This
works whether it's a data attribute on the instance, a data attribute on
the class or a superclass, an instancemethod, classmethod, or
staticmethod:

    obj.attr

Having all of obj.attr, obj$attr and obj^attr *does* reek of perl's
$var, @var, %var distinction (which I have never bothered to
understand).

To me it looks like you've eliminated/combined one thing (instances +
classes become objects) but as a result you've had to invent two new
kinds of complication.

What may have made people jump to a conclusion about $ is that you wrote
something like "$ will remind users of $elf".  This reeks of Perl's bad
explanations of why all their internal variables with punctuation names
are really mnemonic for something:
       $/      The input record separator, newline by default.
               (Mnemonic: / delimits line boundaries when quoting poetry.)
       $.      Current line number for the last filehandle accessed.
               (Mnemonic: many programs use "." to mean the current line
               number.)
Yeah, right.

Jeff
[*] Yes, I know full well there are other ways you can do it
getattr(obj, "attr"), obj.__dict__['attr'], etc, etc.  My point is,
then, that everything can be done with a single "dotted name" syntax.




More information about the Python-list mailing list