New statement proposal for Python

Remco Gerlich scarblac at pino.selwerd.nl
Sun Jun 17 05:44:06 EDT 2001


David LeBlanc <whisper at oz.nospamnet> wrote in comp.lang.python:
> As for the distinction between const(ant) and alias: Perhaps it's a 
> matter of aesthetics, but somehow alias is more descriptive then const 
> since it suggests the substition that's happening. Further, it's 
> incorrect to call "alias true: not 0" a constant imho. To further 
> belabour (with a tip of the hat to the english cousins) the point, it 
> read so nicely to be able to say "if something is true" rather then "if 
> something is not 0" (saves on typing too :-)).

That should read "if something:".

I think 'is true' is bad for a few reasons:
- You rely on an implementation detail, namely that two instances of the
  number 1 will be interned to the same object; that might change. 
  '== true' is better.
- 2 and "whee" are just as much true in Python, but your 'if' treats them
  as false.
- Something like 'if (a and b) is true:' does not do what it seems to do,
  since boolean operators don't return 0 or 1, except for 'not'.
- The whole test for truth is redundant, since that's what 'if' does...

For these reasons, never make #defines (aliases) for true and false.

More in general, your constants are just variables that look like variables
but are protected from rebinding. That's just not in the Python spirit, imo.
Just use some convenction like ALL_CAPS and then don't rebind them...

I think you don't have much experience with Python yet, but come from some
other language and think you see something missing. In your example aliases,
you called a dictionary a tuple (I believe that was you, anyway)... Just code
Python for a while and see that it is never a problem.

> Finally, this wouldn't break any code, nor would anything (excepting 
> perhaps peer pressure) force anyone to use it.

Introducing a new keyword always breaks lots of code.

-- 
Remco Gerlich



More information about the Python-list mailing list