Are reference cycles bad form?
Manuel Garcia
news at manuelmgarcia.com
Fri Apr 18 19:43:42 EDT 2003
I would like to ask the group, are reference cycles bad form?
I am debating whether to give a 'child' object a reference to its
'parent' object during creation of the 'child'.
Before Python had garbage collection, I wouldn't dare make reference
cycles. Rather than create a reference cycle that I would have to
manually break later, I would just make my algorithms a little smarter
so they could figure out the 'parent' without help from the 'child'.
Python now has garbage collection, and I don't have to worry about
creating cycles, but is it bad form to create these cycles when I can
just make my algorithms a little smarter?
Using the 'weakref' module seems silly. I have complete confidence
with Python's garbage collection, so why slow things down with extra
indirection?
I will probably refactor the algorithms with and without the 'child'
-> 'parent' reference, and see which I like better. (Sometimes a
spiderweb of references is more of a crutch than a help.)
But as a general pricipal, is a design without reference cycles better
than a design with them?
(Uh oh, I am having a Visual Basic flashback... shaking and cold
sweats... ;-)
Manuel
More information about the Python-list
mailing list