Attack a sacred Python Cow
pavlovevidence at gmail.com
Sat Jul 26 10:19:05 CEST 2008
On Jul 24, 1:41 am, Jordan <jordanrastr... at gmail.com> wrote:
> Except when it comes to Classes. I added some classes to code that had
> previously just been functions, and you know what I did - or rather,
> forgot to do? Put in the 'self'. In front of some of the variable
> accesses, but more noticably, at the start of *every single method
> argument list.* This cannot be any longer blamed as a hangover from
> Java - I've written a ton more code, more recently in Python than in
> Java or any other OO language. What's more, every time I go back to
> Python after a break of more than about a week or so, I start making
> this 'mistake' again. The perennial justification for this 'feature'
> of the language? That old Python favourite, "Explicit is better than
I'm sure some people use that argument, but in my observations the
more common justification for explicit self is that makes code easier
to read, by making it obvious that something is a class attribute
instead of a local or global variable.
Your claim is that self makes code a lot harder to write, but you've
disregarded the viewpoint of the reader altogether. You probably are
aware that there is another Zen that says "Readability Counts". Would
you also suggest that Zen needs to be done away with?
> If there was one change I could make to Python, it would be to get
> that damn line out of the Zen.
Personally, I think you've applied it to things that it wasn't really
intended for. It's mostly applies to things like language syntax,
type conversions, and other semantics. For instance in Perl there are
cases where you can omit quotes around strings; that'd be a major no-
no in Python. Or how about this:
a = 1 # a is an integer
a += "hello" # oops, now it's a string
Let me suggest that such things are a Very Bad Idea and so that line
is better left in place.
More information about the Python-list