No Thoughts about Everything

Dave Brueck dave at pythonapocrypha.com
Wed Feb 25 12:46:03 EST 2004


Bernhard wrote:
> >If you want something to stay constant,
> >just don't change it.
>
> To my regret in programming in large, sometimes distributet groups and over
longer time on a huge Project it is
> not *my choice* to make the decision not to change a variable. It is a fact
that very often the same names for
> variables and so on are used from different persons in an project, so side
effects are only prevented by encapsulation
> and or make variables constant. (Usually people use uninspired the ever
repeating x,y, z or a,b,c and so on.)

This is not a problem to be solved by a programming langauge IMO. If an
organization cannot set and follow simple coding standards, then it has much
larger problems to worry about. Seriously.

As for the given example, the point (sorry for not explicitly stating it) was
that to get a "constant" value, simply have a coding standard that says that
VARIABLES_LIKE_THIS are constants. It's as simple as that really (and it
enables you to have pseudo-constants as well, as in variables whose values are
constant during runtime, but whose values don't have to be specified _until_
runtime - like configuration options).

> >class Foo:
> >  BAR = 10
>
> I tried that in the following in the following prog:
[snip]

Right, you violated the coding standard. :) That's why I said that in _theory_
it's not constant, but _in practice_ it is. The code you posted (wherein you
change the constant's value) doesn't happen in practice. (seriously - we've
followed this coding practice literally for years without *any* incident - even
newbies pick up on it without being told explicitly not to do it).

Nobody is accidentally going to override a constant value. I have not seen any
cases in real applications where I need the language or its compiler to enforce
constantness. It might be useful for purposes of optimizations, but that's a
different topic altogether.

Ask yourself: what do you actually gain from having the compiler enforce
constantness? And is it protection from an actual problem or is it protection
from a symptom of a larger problem?

-Dave





More information about the Python-list mailing list