What rules to follow to avoid block-closure problems?

Amos aaamos at gmail.com
Sun Jan 13 07:42:48 UTC 2008

On 1/13/08, itsme213 <itsme213 at hotmail.com> wrote:
> I got bitten again (this time not in my seaside code) by nested blocks not
> working as expected. Ouch, debugging that was painful.
> Is there a *simple* rule to follow to avoid this? Should every use of nested
> blocks be replaced by a self-message (with parameters for all the block
> context needed) that does the same? Would be a shame, but if it guarentees
> safe code I will gladly do it.

Debugging blocks can take a bit of getting used to, but once you get
how blocks work, you won't even think about it any more. And blocks
are one of the things that make Smalltalk so powerful, so they should
not be avoided by any means, imho.

Actually, stepping through some code containing blocks will probably
help you understand block closures better. Just step into the parts
where blocks are being sent to an object, and in the method "behind"
it, step over message sends until you get to the point where #value is
sent to the block. Step into that and you'll be back in the message
you started, only "inside" the block. The same principle works for
nested blocks, although obviously sometimes it can take a few more
clicks to get to where you want.

Let me know if that doesn't explain it well enough and I'll try to
come up with an example... ;-)



More information about the Squeak-dev mailing list