More random python observations from a perl programmer
eric at userland.com
Sun Aug 22 20:20:03 CEST 1999
On Sat, Aug 21, 1999 at 09:25:25PM -0400, Tim Peters wrote:
> > Copying things not producing a copy is well, not what non-serious
> > programmers immediately think of.
> Patience, here. People will repeat this until it sinks in <wink>:
> assignment never copies in Python. It just binds a name to an object. This
> is something many (by no means all) people do struggle with at first, but I
> think it's because it's *simpler* than what they're expecting, and it takes
> some time before they stop trying to apply the overly convoluted mental
> models they bring with them from other languages. Persist, and the light
> will eventually dawn!
Well, I'm a LISP and Dylan programmer, so I expected things to work that
way. :-) But I've been teaching Python to a few non-programmers, and they
seem to figure out references pretty quickly. I have them type:
x = [1, 2, 3]
y = x
y = 10
If they look confused, I just say, "Well, you only created one list here.
The variables are just names for it." They say "Oh", grasp the concept, and
move on to the next topic.
References are very simple. It's unlearning what you already know about
variables that causes people trouble. Python itself is a very learnable
language, at least for complete novices.
> Python isn't particularly concerned about being obvious at first glance
> (*no* computer language could be deluded enough to claim that!); it's more
> concerned with notations that, once mastered, are very hard to forget or
> misuse by mistake.
Guido was very clever (at least I think so). I've taught a few people the
basics of programming, and Python makes things so easy for the student.
Python is so *tiny*, and people can learn it in chunks.
You can give somebody a listener, and tell her to type things. She can
study one thing at a time. It's as if each little bit of the language
(functions, variables, expressions, statements, data types) was designed to
be separable from every other bit.
Perl's not a bad teaching language, but novice programmers (at least in my
experience) can't seem to form a mental model of "how it all works." Larry
Wall, being a very smart linguist, would say that such a mental model is
unnecessary--you can speak perfectly comprehensible English without having
studied grammar. I think I disagree with Larry: programming's not quite
like a natural language, and some people benefit from a global
understanding of how things work.
Then again, it may have something to do with the people I've been
teaching. In almost every case, they want to learn programming (and/or
Linux) because computers were mysterious to them and they wanted to
discover some simple, general principles. Unix is good for this, and so is
Python. But back when I tried to teach people Perl, a funny thing happened:
they learned how to program (more or less), but they didn't ever jump up
and say, "Oh! Programming is simple!" Programming stayed mysterious for
them. Of course, this probably has more to do with my teaching than it does
with Larry Wall's fine work. :-)
Now, Tom undoubtably experiences Perl the way I experience LISP (but more
so, because he's a better hacker than I am): it's lucid and clear, and
every feature makes sense. There are no mysteries. But some of his Perl
snippets have made my skin crawl--I can understand what's going on, but
there are so many complicated concepts crammed into such a tiny space. It's
not something I could *explain* to a novice without taking a two-day
detour. C++ is the same way--you're trying to explain what a "parent class"
is, but then you need to explain "empty virtual destructors", which
probably requires a short detour to talk about vtables and how a C++
So, my new Python motto: "Teach people Python, and let sleeping dogs lie."
More information about the Python-list