Exception handling wart in Python

Terry Reedy tjreedy at home.com
Fri Nov 2 09:47:45 EST 2001


"Leo Lipelis" <aeoo at myspamrealbox.com> wrote in message
news:pan.2001.11.02.01.07.16.112.704 at myspamrealbox.com...
> Besides, let's not compare to another language with even more
problems and
> say, but they are worse, thus we don't need to improve :).

Fair enough.

>Who cares if  Java is too verbose?  Point is, Python can be made
better
> by getting rid of the "self.__" in front of every object attribute.

You are welcome to use 's' or whatever instead of 'self' (as I do for
private use), thus saving yourself 3 keystrokes each time.  Except for
magic methods, you only need '__' if you want to enforce
private-variableness.  I do not find 's.' terribly burdensome.  With a
good editor, you could translate ^U or whatever to
____<Backspace><Backspace> for magic method names.

However, aside from this, your proposal would eliminate the
distinction between attributes and local/global vars.

>  For instance, why not
> assume that ALL variables are instance variables, and have the other
ones
> use some special notation?  The absolute majority of attributes you
will
> use are instance attributes.  Why penalize the common case?  That's
bad
> engineering.  You should always penalize the fringe case.  Doesn't
that
> make sense to you?  If you have 2 class attributes and 20 instance
> attributes, why would you penalize the 20 instead of 2?  That's
insane.

Do you have the false idea that instance attributes *must* be prefaced
by '__'?  Otherwise, your statements make no sense to me.

In any case, I think that at least half the variable references I have
seen in methods have been to local variables that have been passed in
as arguements or generated by assignment.  The latter includes self
attributes that have localized for efficiency.  IE

  def meth(s, arg1, arg2):
    v1 = s.some_attribute

If s.some_attibute is needed several times (for instance, within a
loop) copying it to a local var saves looking it up over and over.
This is a common idiom among knowledgeable Pythoneers.

Terry J. Reedy






More information about the Python-list mailing list