Teaching programming -- circular data structures
Roy Smith
roy at panix.com
Mon Jul 1 21:41:59 EDT 2002
This is more about how people learn to program than about python, but it
happened in python, and I know folks here are interested in teaching
programming...
There's a guy at work who is mostly a self-taught perl and TCL
programmer. A while ago, I showed him python, and he's very into it
now. We've done a few projects together, of increasing complexity and
sophistication.
Today, we were working on implementing a particularly gnarly algorithm.
We had made some headway with coding it up on the fly, and eventually
ended up abandoning the code because our data structures were a total
mess. So, we sat down at the whiteboard and started to design a set of
classes, with the intent of starting to code again from scratch once we
had a better idea of how the data was to be organized. This is, of
course, how we should have started the first time, but you know how that
goes :-)
At one point, I sketched out two classes, called rule and indicator. A
rule contained (among other things) a list of indicators, and each
indicator contained a reference back to the containing rule. At this
point, things came to a grinding halt when my coworker observed that I
had just created a circular data structure. He was aghast that you
could (although we had no intention to) write things like
rule.indicator.rule.indicator.rule, and insisted that we had to find
some other way to design the data structures so this couldn't happen.
No amount of explaining on my part could convince him that such a thing
wasn't evil, or horribly confusing. Although he could not articulate
exactly what bothered him so much, I think he was vaguely scared of some
sort of infinite loop in the code.
Is this a common thing? I, as an experienced programmer, found the
circular references perfectly reasonable, but it seemed to blow his
mind. Have people teaching programming (or, more precisely, data
structures) see this before; that people have problems understanding
circular data structures the first time they're exposed to the concept?
More information about the Python-list
mailing list