having both dynamic and static variables

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Mar 6 02:58:21 EST 2011


On Sat, 05 Mar 2011 20:33:49 -0800, Westley Martínez wrote:

> On Sat, 2011-03-05 at 18:37 -0800, John Nagle wrote:
>>     It's worth having some syntax for constants.  I'd suggest
>> using "let":

+1 on syntax for constants. -0 for "let". I'd prefer something more 
explicit, like "const".

> I'm against constants, for the purpose of "programmers should be smart
> enough to not set a variable to another value that should be static",

Most programmers are smart enough not to rebind names which should be 
constant. The problem is, how do you know which names should be constant?

A naming convention like ALL_CAPITALS helps, but not everybody sticks to 
the convention. Also, if constants are enforced by the compiler, that 
opens the door for many optimizations that currently Python can't do even 
in principle.



> but if Python were to have constants I think it would be better to use
> something more descriptive than 'let'. Also, because the defined
> constant is static, I think it would be better to use 'is' instead of
> '='. Example:

No, we're talking about assignment, not a comparison operator. The `is` 
operator is equivalent to `==`, equals, not assignment.


-- 
Steven



More information about the Python-list mailing list