The “does Python have variables?” debate

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 8 10:22:00 EDT 2014


On Thu, 08 May 2014 23:46:31 +1000, Chris Angelico wrote:

> On Thu, May 8, 2014 at 11:18 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> So... although I don't go quite so far as Ben in thinking that using
>> the term "variable" in describing Python is harmful, I will say that
>> the "no variables" meme is *useful* precisely because it is so shocking
>> and so counter-intuitive that it forces[1] you to question your
>> assumptions about how programming languages operate.
> 
> Maybe the shock value is helpful, but that doesn't mean the statement's
> strictly correct. It seems that every time we have one of these
> discussions, someone claims that Python's name->object bindings are
> utterly unique in the world of programming,

I'm pretty sure I've never seen anyone make that claim explicitly. I'm 
not even sure anyone has implied it, although I have seen people counter 
the "no variables" meme with the *accusation* that the meme wrongly makes 
Python out to be radically different from other programming languages.

I think there is a kernel of truth to that accusation. I know that when I 
was first exposed to this meme, I got the impression that Python was, if 
not unique, at least rare. Eventually somebody challenged that meme by 
pointing out that Ruby, Javascript and Java use the same model, and that 
it is pretty much standard for high-level languages.


> which is patently false, as
> a number of other languages do the same thing (often calling them
> variables). So what does "Python doesn't have variables" mean? Really
> it's "Python doesn't have variables like C's or Pascal's".

Which is what both Ben and I *explicitly* say, when we use this meme. I 
won't speak for Ben, but I admit that when I first came across this meme 
some years back, in my enthusiasm and ignorance of other languages I may 
not have qualified it. I was young, or at least younger, and my mental 
model of "variables" was 100% Pascal, so to me, the idea that Python so-
called "variables" weren't *really* variables ("no true Scotsman") was 
quite heady and I may have been a bit over-enthusiastic for it.

But you know what? It takes a lot of discipline and effort to avoid using 
the term "variable" in favour of "name binding". It's not just a matter 
of extra typing, sometimes the word *variable* as in "something that 
varies" is exactly the right word and trying to find an alternative is 
too hard. So I've settled on what I think is the right strategy:

* if I need a word for "something which varies", I normally 
  use "variable";

* if somebody appears to have misunderstood Python's semantics,
  often because they're applying C-like semantics to name bindings,
  I'll explicitly say that Python doesn't have variables in the C
  sense of fixed memory locations known at compile-time, and 
  introduce them to the idea of run-time "name bindings".


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list