[TriZPUG] "Use of the Words 'Variable' and 'Assignment' Considered Harmful in Python"

David Handy david at handysoftware.com
Thu Sep 29 17:13:49 CEST 2011


On Thu, Sep 29, 2011 at 09:33:47AM -0400, Tom Roche wrote:
> 
> Chris Calloway Wed, 28 Sep 2011 13:50:36 -0400 (rearranged, desubjunctivized)
> > "Use of the Words 'Variable' and 'Assignment' Considered Harmful in
> > Python." It's one of my pet peeves and it only got stronger last
> > night when binding to an identifier was referred to as "storing in
> > memory."
> 
> "Variable assignment" is a common informatic idiom, and it *seems* pretty similar to what's happening in
> 
> $ python -c 'i=1 ; print i'
> 
> no? So ... what's the harm?

The potential harm is that it tends to communicate the wrong conceptual
model. This isn't like C or assembly language, where there is a memory
location labeled "i" and we're stuffing the integer 1 in that memory
location. Consider:

>>> i = 1
>>> a = [i]
>>> i = 2
>>> print a

What happens next? If you are thinking in the C programming model, as if
object references were pointers to memory locations, you would expect that
you just changed the contents of memory location "i". If so, you would
expect this output:

[2]

But instead, you get this:

[1]

You must have a proper concept of Python's programming model in order to
predict what a python program will do. "i" is a reference to an immutable
integer object. Binding a name to an immutable object is hugely different
than storing an integer in a volatile memory location. We're insisting on
using the right words in order to communicate the right concept.

(Teaching programming is my hobby, sorry if I'm getting too pedantic.)
David H


More information about the TriZPUG mailing list