Teaching programming -- circular data structures

Benno benjl at cse.unsw.edu.au
Tue Jul 2 01:17:03 EDT 2002


Roy Smith <roy at panix.com> wrote in message news:<roy-21A543.21415901072002 at reader2.panix.com>...
> 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.
> 
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?

Looks fine to me! I use them all the time :) (Well OK, I sometimes use them
when appropriate).

The main thing to worry about here is that you can no longer rely on python
to clean things up for you. (Reference counting no longer works.) So you
either need to use garbage collection, which detects circular dependancies.
Or explicitly break the circ. depends but setting them to None. Or finally
use the weak refeerences package to avoid the mess.

Benno

(Not sure that answered the actual question, but anyway!)



More information about the Python-list mailing list