[Edu-sig] what is a "variable" in Python?

kirby urner kirby.urner at gmail.com
Mon Feb 15 16:41:06 EST 2016


No need to say "sorry" as if an honest disagreement were a cause for
regret.  I enjoy diversity.  What would life be without different
perspectives?  Plain vanilla.

I'm familiar with the mental model of which you speak and was for years
myself not a Python programmer, with miles of source code to my name.  But
so what?  Python is different than C which is different than Erlang and so
on.

So be prepared, ye novices, to pay special close attention to how we say
"variable" and/or "keyword" or whatever.

Like we both agree "keyword" means something else entirely in Clojure.  And
so it is with these computer languages:  all subtly parallel universes of
each other, in how they sling the jargon:  familiar, yet strange.

"Yes, exactly, so pay close attention" -- that's me reminding even seasoned
C programmers, whom I have in my <guild /> classes (or class, I'm new there
[1]), that each language is a little different.

We also both agree that "immutable" versus "mutable" is a characteristic of
objects, not the "remotes" (objects as TVs, usually quite mutable on
average), not the luggage tags (objects = suitcases).

Names are neither mutable nor immutable just easily re-assignable.  I pull
an "X" off a 3 and stick it to a steam engine instead, they're both
objects, no problemo.

But some are mutable, change state.  Inattention to this difference,
postponing it as "advanced" is highly inadvisable, even dangerous.  Learn
the difference right away!

And why not.  The assignment part just was *not* that hard.  Removing the
"container" metaphor (as if we needed "variables" in addition to "names and
objects") will for some students be the stroke of lightning that finally
makes it all come together.  Why?

Because containership is at cross-purposes to how Python never copies
implicitly, when you keep assigning names to names ala A = B.  How do five
"containers" all "contain the same thing"?  That's the core of the "buckets
versus postits" controversy and whereas you say you disagree, you have yet
to take that bull by the horns.  The assignment operator is not in your
favor as Label = 3 is precisely affixing a tag to 3, not embracing and
containing 3 in some spooky object called Label (take that route and you're
forever the dazed and confused C programmer in Python Land).

You should expect a percentage of your students to achieve illumination by
this insight.  You defend a conventional dogma and disagree with my
teaching.  I'm proud of that difference and charge yet more money for that
reason. So again, don't be sorry.  :-D

Kirby

[1] https://www.flickr.com/photos/kirbyurner/albums/72157664250599655



On Mon, Feb 15, 2016 at 12:19 PM, Litvin <litvin at skylit.com> wrote:

> Sorry, I don't agree.  Thinking of variables as named containers is not an
> "incorrect mental model" but a useful metaphor for teaching programming to
> novices.  In my mental model, variable is called a "variable" because it
> can hold  different values at different times.  This has nothing to do with
> immutability.  Immutability applies to objects, not variables; an immutable
> object cannot change its state after it has been created, regardless where
> it is stored.  A tuple is immutable but a variable can hold different
> tuples.  Immutability is a more difficult, OOP concept, and the discussion
> of immutability does not belong with  an introductory topic of variables.
> _______________________________________________
> Edu-sig mailing list
> Edu-sig at python.org
> https://mail.python.org/mailman/listinfo/edu-sig
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20160215/2086ff14/attachment.html>


More information about the Edu-sig mailing list