On Thu, 01 Mar 2018 16:49:35 -0800, Rick Johnson wrote:

> Remember, the challenge is _not_ simply a matter of circular references
> (there is literally tons of Python code out there which creates CRs for
> various reasons), no, the challenge is to create a custom class which
> references _itself_, and then explain (or demonstrate) how such a thing
> serves a practical purpose.

Nobody cares about this challenge, since nobody but yourself seems to 
think that it is important or necessary whether "self.foo = self" 
specifically gets used or not. It's just an illustration of an entire 
class of cycles.

If your language can deal with cycles, then it can naturally deal with 
the case `self.foo = self` too, and without needing any special handling. 
There's no benefit to banning this one special case when an infinite 
variety of other cycles are possible. We could prohibit it, by adding the 
check:

        if value is self:
            raise RickError('self.foo = self not allowed')

to every attribute assignment, but for what purpose? Doing so doesn't 
prevent cycles, it doesn't avoid a common source of bugs, and it 
needlessly slows down every attribute assignment.

And for the record, consider a tree of nodes, where each node points back 
at the root of the tree, which is also a node. So what does the root node 
point back at?


-- 
Steve

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to