No Thoughts about Everything

Richie Hindle richie at entrian.com
Wed Feb 25 11:01:36 EST 2004


[Bernhard]
> [snip 73-line question on how to do "static final" in Python]

The answer:

c = 2.99792458e8

Seriously, you are trying far too hard.  Python is not a
bondage-and-discipline language.  If you want something to stay constant,
just don't change it.

I could be wrong, but I believe the only reason the question occurs to you
is that you're coming from Java, which makes a point of supporting such
ideas.  In real-world programming you just don't need that kind of thing -
if you don't trust the code to work forever then you write unit tests, and
they will test all aspects of your code, not just the careless mutation of
the speed of light.

And the same goes for *teaching* idiomatic Python - if you simply define
'c' at the top of your module, how many students would ask "but what if I
later change the value of 'c'?"  The question would only occur to people
converting from B&D languages.

-- 
Richie Hindle
richie at entrian.com





More information about the Python-list mailing list