"as" keyword woes

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Dec 4 09:45:46 EST 2008


On Thu, 04 Dec 2008 20:53:38 +1000, James Mills wrote:

> Readability of your code becomes very important especially if you're
> working with many developers over time.
> 
> 1. Use sensible meaningful names.
> 2. Don't use abbreviations.

This is excellent advice, but remember, what is a sensible meaningful 
name is domain-specific. In a maths library, this would be sensible:

def poly(x):
    return 4*x**3 -2*x**2 +3*x -7

and this ridiculous:

def poly(real_number):
    return 4*real_number**3 -2*real_number**2 +3*real_number -7


Sometimes there are name clashes between keywords and sensible names in 
your problem space. I'm sure every regular Python developer has found 
themselves writing something like:

prnt print_ print2 
cls klass class_ 

or similar. In the standard library, the random module uses an argument 
"lambd" because lambda is a keyword.



-- 
Steven



More information about the Python-list mailing list