Simberon Design Minute
 

Block Abuse

Blocks are one of the key language features of Smalltalk. They allow you to encapsulate an operation into an object to be performed whenever you wish. Usually, blocks are evaluated further down in the call tree. In other words, you pass a block as a parameter through a number of methods and eventually one of the methods evaluates the block and returns. It's possible, however, to store a block into a variable and use it even after the method that created it has returned. This is where you can run into trouble. Blocks are hard to figure out by just looking at them. If they are in a data structure, an inspector can show you that an object is a block but can't easily show you what will happen when you execute the block. The only way to determine what it does is to evaluate the block and run through it with a debugger. Blocks also cause problems when you try to persist them. It's hard to map a block into the database and back without having problems. In the end, you should consider the costs of using blocks before committing to use them as data in your application.

Download