Back in the old days of Smalltalk, you would declare all of your temporary variables at the top of the method regardless where you used them within the method. In more recent years, it's been possible to declare variables in the scope of a block. Many developers, though, still choose to declare the variables at the top of the method. I much prefer defining them to be local to the block where they are used. It's a bit more efficient to have the variables declared in the block but more importantly, it better documents the scope of the variable and shows more clearly where and how the variable is used. In general, techniques that make the code more understandable make for a better design.
Download