Encapsulation unpythonic?

Rhodri James rhodri at wildebst.demon.co.uk
Mon Sep 2 19:29:42 EDT 2013


On Sat, 31 Aug 2013 12:46:52 +0100, Steven D'Aprano  
<steve+comp.lang.python at pearwood.info> wrote:

> # THIS DOES NOT HAPPEN IN PYTHON
> # or any other language, as far as I am aware
> x = 23
> y = x  # y now has the value 23
> x = 42  # change the value of the object  ### NOT SO! ###
> print y
> => prints 42

Not directly, but FORTRAN did (does?) allow you to achieve this  
oh-so-undesirable result indirectly.

FORTRAN passes arguments to functions and procedures by reference.  That  
includes passing constants, which effectively get put into hidden  
variables and passed across.  Changes to the "constant" parameters in the  
function can happen just as with any pass-by-reference, which would be  
fine if you promptly threw the constant away.  Unfortunately smart  
compilers used to (still do?) keep pools of these common constant  
"variables" around rather than creating new ones all the time, so changes  
to "constants" persisted.  Many's the poor natural scientist who was  
perplexed to find that 0 suddenly had the value 1!

-- 
Rhodri James *-* Wildebeest Herder to the Masses



More information about the Python-list mailing list