python improvements (Was: Re: New Language)

Russell E. Owen owen at astroNOJNK.washington.edu.invalid
Mon May 15 14:30:41 EDT 2000


In article <LNBBLJKPBEHFEDALKOLCOEAKGAAA.tim_one at email.msn.com>, "Tim 
Peters" <tim_one at email.msn.com> wrote:

>[Steven D. Arnold]
>> 1. I'd like an equivalent to perl's "use strict" pragma.  It's
>> annoying to have to be so paranoid about making a typo in a
>> variable name.
>
>[Martijn Faassen]
>> How exactly would this work? It would seem hard to make this work
>> right in a dynamic language, but perhaps I'm missing some simple
>> strategies.
>
>Perl simply (& simplifying a bit) whines about vrbl names that appear
>uniquely within a file.  They're usually misspellings, but sometimes not.
>Tools to do that for Python have been written several times too, but never
>caught on, despite that they've even found long-standing bugs in the std
>Python library.  Check out Aaron Watters' pylint for the best of that 
>breed.

Thus demonstrating the utility of having such functionality built into 
the language, preferably with enough power to find variables that are 
being read without being set.

I would personally like to be required to declare variables before using 
them, a la smalltalk. (Just declare the names, not specify a "type".) It 
would greatly simplify this kind of error checking.

(Not being forced to declare variables is dangerous, as has been amply 
demonstrated by FORTRAN over the years. That language finally allowed 
one to optionally force declarations.)

Also on my wish list (inspired by Smalltalk):
- class instance variables and class variables are declared as part of 
the class declaration and nowhere else. The current system seems 
dangerous, especially for class variables. It's too easy to mis-type a 
variable name and so create a new one.

- class methods (e.g. ClassName.doSomething(...)). Often useful where 
global functions might otherwise be wanted. By requiring the class name 
one gets namespace protection and categorizes the function as relevant 
to objects of the given class.

- class methods don't need "self" as the first argument; it's a keyword 
that is autmomatically defined. Less confusing because the caller's 
argument list matches the receiver's argument list. Also, by forcing a 
keyword ("self") to be used, improves code uniformity.

-- Russell



More information about the Python-list mailing list