Developers SIG
July 2, 2002

Announcement

This meeting of the Developers SIG will include an overview and discussion of three software engineering "best practices": the code review, refactoring, and unit testing. Keith Alcock will provide background information on these practices and during the discussion demonstrate refactoring tools and a unit testing framework. This will be a interactive event and some preparation is encouraged, but not required. Please see http://www.keithalcock.com/tcs/devsig/02Jul2002 for materials including the code to be reviewed and links to related resources.

Biography

Keith Alcock has written software for fun and profit (often simultaneously) for over twenty years. He currently works as a consultant for the likes of Language Technologies, Inc. with a preference for the area of computational linguistics. He can be contacted at keith@keithalcock.com.

Materials

The code we will be reviewing is based on the article "Opening Disaster" published in the July 2002 issue (volume 10, number 7) of Software Development magazine. The article uses Java as the implementation language for the Sieve of Eratosthenes algorithm, a method used to find prime numbers. I have converted the code from Java to Smalltalk for use at this meeting and the source code for the two classes, GeneratePrimes and TestGeneratePrimes, can be downloaded and printed from this site in preparation for the meeting. Although preparation isn’t required for this mock review, it would be required for a real one and the more people who have read the code and thought critically about it in advance, the more realistic the review might be.

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.

Follow-up

In preparing for this talk, I noticed that my translation of the original Java code could have been better, so that document has been updated and it may not be the same as the hardcopy that was handed out at the meeting.

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.