The “does Python have variables?” debate

Ned Batchelder ned at nedbatchelder.com
Tue May 6 21:19:36 EDT 2014


On 5/6/14 7:55 PM, Ben Finney wrote:
> Ned Batchelder <ned at nedbatchelder.com> writes:
>
>> This meme bugs me so much. Python has variables. They work differently
>> than variables in C.
>
> Which is why it's useful to intervene right at the start when someone
> comes in with assumptions about “variables”; it's better that they
> discard that baggage and learn about reference binding, instead.

Where do you draw the line?  Python ints work differently than C ints, 
but we don't seem to mind using the same word for them. Same for strings 
and functions.  Python's classes work differently than C++ or Java's, 
but we don't say that Python has no classes.

And let's not discuss Lisp's lists, Haskell's functions, or Modula-2's 
modules.

So many terms are used and re-used, and each language has differences. 
Why is "variable" sacrosanct and can only be used to describe C 
semantics, but we're OK reusing class, int, and function?

>
>> In fact, they work by having names bound to values.
>
> My position is that this concept is sufficiently different to what most
> newcomers to Python mean by “variable” (those who have the term at all;
> and for those who don't, no need to introduce potentially-confusing
> terms) that it's better to avoid that term entirely and immediately use
> more-accurate terminology.
>
>> If you want to insist that Python has no variables, you will have to
>> also say that neither do Javascript, Ruby, Java, PHP, etc.
>
> I don't know enough Ruby to comment there. For Java, Javascript, PHP,
> they *do* have variables that work pretty much as expected by these
> newcomers: the variables are declared and exist before a value is
> assigned, they have the “box containing a value” conceptual model (as
> contrasted with Python's “value with sticky-notes attached” model), the
> “how do I pass by reference or by value?” question is meaningful — all
> of these are significantly different in Python, so the term “variable”
> is useful in those other languages but mostly just a confusing obstacle
> in learning Python.

As Chris A. has pointed out, Javascript works like Python, and not much 
like C.

>
>> And if Javascript has no variables, what does the var keyword mean?
>
> Exactly; JavaScript *does* have variables, in the ways Python does not.
>


-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list