Re: The “does Python have variables?” debate

Chris Angelico rosuav at gmail.com
Thu May 8 10:51:01 EDT 2014


On Fri, May 9, 2014 at 12:22 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>> 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.

You might, but he didn't. Compare what he wrote recently:

On Wed, May 7, 2014 at 9:55 AM, Ben Finney <ben at benfinney.id.au> wrote:
> 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.

Implication: That Java, JavaScript, and PHP, with Ruby as the only
omission, all have C/Pascal variables, and Python doesn't. Reality:
Java and JavaScript follow Python-like semantics (at least as regards
boxed objects, in the case of the former; unboxed integers in Java are
more akin to C's integers), and PHP is... well, PHP is PHP, I don't
think there's really much comparison. But even in PHP, the 'object'
type more-or-less follows Python-like semantics. (There are some
extreme weirdnesses as regards arrays, which are notionally copied
whenever they're passed around, but it seems in most cases to be
optimized to copy-on-write. I'm not sure what happens when you use a
PHP reference. So I'm just going back to "PHP is PHP".) Since Ruby
also follows Python-like semantics, as do Pike, and (IIUC) C#, and
many other languages, the overall result is that Python is far from
unique, and that the explicit "like C's or Pascal's" is important.

And then the question becomes: How useful is it to argue that "Python
doesn't have variables like C's or Pascal's" to someone who has never
used C or Pascal? And if that person has experience with JavaScript's
variables, is it as counterproductive to say "Python doesn't have
variables" as to watch the Ruby people argue that it's really called
pass-by-reference?

ChrisA



More information about the Python-list mailing list