A feast inside itself
transcript
Someone adds the family feast into its own combo. The combo is already inside the feast. Nothing complains. Then, a day later, the cart screen freezes.
Adding is just a list append. So it worked. The tree is quietly broken. The cart asks for the price. It asks the feast, and the feast asks the combo. The combo asks the feast again. Which asks the combo again. For ever. Stack overflow. And a frozen screen.
The fix is in add. Before a group takes a child, it walks up its own parents. The combo is asked to add the feast. The combo's parent is the feast. That's the very child being added. So refuse it, and name both groups in the message.
One walk up, and only when you add. It costs the depth of the tree, no more. Pricing never checks anything. The tree can't be broken.
Not where it's read. By then it's far too late. Refuse at add.
Full breakdown in the lecture.