[Edu-sig] Edu-sig Digest, Vol 39, Issue 2

kirby urner kirby.urner at gmail.com
Tue Oct 3 01:04:12 CEST 2006


> Anyway, I would advocate the "as opposed to" be integrated into such a
> presentation.
>
> Art
>

Yes, once bitten in the butt by the fact of a two handled mug, then
comes the question:  "so how do I make sure each handle gets a mug to
itself?"  (as in "why should we share the same beer?").

At this point, we have a couple of trix, one of which you mentioned
(use list(input) to return another list).

Or we might import the copy module.

Or we might "take the whole thing as a slice" i.e. newlist = oldlist[:].

However, the list and slice functions aren't generic enough to work
for generic objects.

I think the key here is to refer to "=" (the equal sign) as an
operator, i.e. a "doer" (we're not asserting the identity of two
objects (as in pre-computer algebra) but assigning a handle to a piece
of memory, giving it a name.

I'm thinking astronomy might come in useful here.  Two namespaces
(mythologies) might connect the stars into completely different
creatures, surrounded by their own respective stories.  You can get
away with this, even if we don't admit to parallel universes thereby
(same stars, different tellings).

Actually *duplicating* a piece of memory (wasteful?), to make the same
contents reside elsewhere (why?), with its own handles, is considered
a semi-esoteric move in Python, not something you'd necessarily need
right out of the box.

There's a builtin bias against it (duplication), because Memory should
be retreated with respect as a finite resource, not squandered
unnecessarily.

But if you *really* need to clone a piece of memory (vs. simply assign
it a new handle), then by all means, import the copy module and even a
deepcopy if you need to.

You have that freedom.  But it's a step away from an everyday operation.

As far as beginners are concerned, they may come to Python with the
expectation that duplicating objects willy nilly is the mark of a good
program ("memory is cheap" we're always saying these days).

Setting them up for a surprise may actually be good pedagogy.

Maybe some teacher text (not necessarily printed) wants to do a "Snake
Bite" icon, with the spin that here's a potential pitfall, but also a
useful lesson, should you fall into it (we learn from these snake
bites and move on).

Kirby


More information about the Edu-sig mailing list