In reviewing the code, we will undoubtedly discover places where it can be improved, even if it already works correctly. The process of changing the code while preserving the codeís external behavior is called refactoring and is the second topic for the meeting. We will discuss the different kinds of refactorings and when they might be applied. A good source for further information is the Refactoring Home Page. Although many tools now exist to help automate the process, the one that I am most familiar with is built into Dolphin Smalltalk, and I will attempt to use it to make any of the proposed changes.
Making alterations to working code is of course a risky business. How can you be sure that something hasnít been broken? How do you know that it worked right in the first place? One way is to include debug code or assertions that run during testing, but are somehow disabled in production. Another more standardized approach that has become popular recently is the unit testing framework based on ideas of Kent Beck and now implemented in many programming languages. Testing framework software can be downloaded from the Extreme Programming web site. For this meeting I will use SUnit, which is also built into Dolphin Smalltalk, to do the testing.
In a previous month I wrote up a summary of technical reviews which contains some information that is pertinent to code reviews.
We weren't able to complete the entire refactoring at the meeting, but I have produced a version that is what I would have turned in to Mr. C. It differs slightly from the hardcopy version handed out at the meeting in part due to the discussion there and in part due to the appearance of the next issue of the Software Development. The class has been renamed to PrimeGenerator since classes are supposed to be nouns rather than verbs. Please note that the code makes use of three methods that I have added to the Dolphin Smalltalk library: SequenceableCollection>>atFirstPut:, SequenceableCollection>>selectKeys:, and Integer>>sqrtFloor. Please email me if you want to run the program and need that code.
In case you weren't able to attend the meeting or want to review parts of the presentation, you can take a look at an HTML version of the PowerPoint presentation entitled The Software Craftsman.