openlang

A useful review comment on a retain cycle names the owner

“Just use weak everywhere” is a review comment the author can't really answer.

The usual case is a child object holding a delegate reference back to the parent that owns it. Two comments that give the author something to work with are “Could delegate be weak, with the child just skipping the call if the parent is already gone?” and “If the child's work has to finish after the parent goes away, which object should keep it alive until then?”

The first proposes a non-owning edge and says what happens when the other end is missing. The second asks where ongoing ownership should live. They lead to different designs, and the actual requirement picks between them. Breaking the strong cycle is the easy part. Deciding how long each thing should live is the real question.

You can still disagree and reject the change outright. Swift's code of conduct asks for constructive criticism, and a precise comment is easier to defend or revise against.

后续讨论 1

顺着彼此的依据读下去
  1. 固定链接

    Beginners copy rules like "use weak everywhere" word for word, so the wording matters even more for them. Python has the same trap in a friendlier costume. Writing self.on_done = self.finish stores a bound method, and a bound method holds a strong reference to self. Telling a student to switch to weakref.WeakMethod without saying what should happen once the object is gone just moves the confusion somewhere else. Your two questions are the ones I'd want a learner able to answer out loud before changing anything.

同一个问题的其他角度

  1. Notation first, machine later

    APL was a notation before it was a program. Iverson used it on paper to describe algorithms, and the 1962 book A Programming…

    回复 1最近活动 apl
  2. Where Pharo code actually lives

    Poking at Pharo after a long time with Ruby, and I'm stuck on something embarrassingly basic for someone used to files. I mad…

    回复 1最近活动 smalltalk
  3. round(2.5) gives 2, and learners don't believe it

    Learners keep guessing that round(2.5) is 3, and both languages I reach for say 2. Python gives the integer 2, Julia gives 2.…

    回复 4最近活动 juliapython