Thoughts about Python

Terry Reedy tjreedy at udel.edu
Tue Feb 24 11:42:32 EST 2004


"Marco Aschwanden" <PPNTWIMBXFFC at spammotel.com> wrote in message
news:15c2d03b.0402240311.395f5382 at posting.google.com...
> I have collected those thoughts. I am sure there are many discussions
> on the "problems" mentioned here.

Yes, there have been.  Do read some if you are really interested.

>*** Problem: clumsy properties for classes

The problem is currently under discussion.  Your fix is based on thinking
'self' to be a keyword, which it is not, instead of a usage convention for
English language programmers.  Python is not <language x>.

> class c (object):
>     def staticMethod(arg1, arg2, ...): pass
>         # self is not handed in... hence I can't use the instance vars

Yes it is and yes you can if this method called on an instance.  You have
simply called the instance 'arg1' instead of 'self'.

>     def normalMethod(self, arg1, arg2, ...):
>         pass

If you follow this by normalMethod = staticmethod(normalMethod), then
'self' is *not* an instance.
Static methods are very rare.  You left out a proposal for the more common
and more useful classmethod.

...
> Many builtins are not necessary.

Many people agree.

> To name a few: min / max / len

But people wildly disagree on which should be axed.

> This functions should be defined on the class:

This syntax uniformatizing suggestion comes up about once a year.  It
overlooks the fact that uniformity is lost as soon as a user writes a
sequence function (for instance, variance()).  I know, we could abolish
functions and only have methods.  But if you want that, choose a different
language.

Even more, It also overlooks the tremendous advantages of generic
programming with Python.  If I write an iterable type, it can be used with
any sequence function, current or future.  Conversely, if I write a
sequence (iterable) function, it can be used with any iterable object,
current or future -- without subclassing or access to source code.  Your
proposed handcuff of requiring a specifc method for each type - function
combinatin leads to an M*N explosion of code and coding work.

Quiz: how would you rewrite map(len, ['abc', (1,2,3,4), [5,6]]) if len()
were a method?

>classes start with an uppercase letter:
> myList = List()

This appears to be a convention or rule you learned from another language.
Though some Python programmers follow it, tt is not part of Python.

Terry J. Reedy







More information about the Python-list mailing list