const objects (was Re: Death to tuples!)

Steven D'Aprano steve at REMOVETHIScyber.com.au
Wed Dec 14 22:20:10 CET 2005


On Wed, 14 Dec 2005 18:35:51 +0000, Tom Anderson wrote:

> On Wed, 14 Dec 2005, Steven D'Aprano wrote:
> 
>> On Wed, 14 Dec 2005 10:57:05 +0100, Gabriel Zachmann wrote:
>>
>>> I was wondering why python doesn't contain a way to make things "const"?
>>>
>>> If it were possible to "declare" variables at the time they are bound 
>>> to objects that they should not allow modification of the object, then 
>>> we would have a concept _orthogonal_ to data types themselves and, as a 
>>> by-product, a way to declare tuples as constant lists.
>>
>> In an earlier thread, somebody took me to task for saying that Python 
>> doesn't have variables, but names and objects instead.
> 
> I'd hardly say it was a taking to task - that phrase implies 
> authoritativeness on my part! :)
> 
>> This is another example of the mental confusion that occurs when you 
>> think of Python having variables.
> 
> What? What does this have to do with it? The problem here - as Christopher 
> and Magnus point out - is the conflation in the OP's mind of the idea of a 
> variable, and of the object referenced by that variable. He could have 
> expressed the same confusion using your names-values-and-bindings 
> terminology - just replace 'variable' with 'name'. The expression would be 
> nonsensical, but it's nonsensical in the variables-objects-and-pointers 
> terminology too.

If the OP was thinking names-and-bindings, he would have immediately
realised there is a difference between unmodifiable OBJECTS and
unchangeable NAMES, a distinction which doesn't appear to have even passed
his mind.

"Variable" is a single entity of name+value, so it makes perfect sense to
imagine a variable with a constant, unchangeable value. But a name+object
is two entities, and to implement constants you have to have both
unmodifiable objects and names that can't be rebound -- and even that may
not be sufficient.



-- 
Steven.




More information about the Python-list mailing list