the annoying, verbose self

Paul Boddie paul at boddie.org.uk
Fri Nov 23 02:18:30 CET 2007


On 23 Nov, 01:41, braver <delivera... at gmail.com> wrote:
> On Nov 23, 1:15 am, Paul Boddie <p... at boddie.org.uk> wrote:
> One wonders whether the people complaining so vehemently
>
> > about self have ever encountered coding style guides.
>
> Dude, I'm also programming in Ada, 83 to 95 to 2005.

It's not often that I get called "dude". ;-)

>  Beautiful language, a living style guide.

Beautiful plumage! [*]

>  I love typing names dozens of
> charactares long -- in Ada.  Ada has scope control, separate
> compilation, renames, overloading, types, etc...  However, in
> scripting languages, it's not cool, and I'd just love to see self hide
> for a bit of a change -- it's a nuisance after Ruby, 's all.  Nothing
> eternal or worth assembling a NASA panel or Python foundation meeting,
> just a li'l respite to make a tiny script more lucid, OK?

Well, it's just a pragmatic decision which exposes the mechanism of
passing the instance, which is typically hidden in most of the other
object-oriented languages. The issue is how you resolve names without
having specific details of which names exist on an object. Consider
this:

  class X:
    def f(value): # in "Selfless Python"!
      attr = value

What is attr? A local, a class attribute or an instance attribute?
Sure, we could deduce that f is an instance method of X, and that attr
could really be "self.attr" or even "X.attr". Languages like Java
remove such uncertainty by forcing the declaration of locals and class
and instance attributes, but Python has no such restrictions - an
instance attribute called attr might be introduced later in such a
program, outside any function or method clearly related to the class,
and we'd need to know about that to make an informed decision in cases
like the one shown above.

Paul

[*] Sorry, but such an exclamation is almost obligatory under the
circumstances.



More information about the Python-list mailing list