Sponsors

Tuesday January 17, 2006
Rescheduled from June
Using Code Metrics for Targeted Code Refactoring

Andrew Glover

Thanks to Andrew Glover for his excellent presentation covering different techniques of spotting bad code. Andrew was flown up to Hartford courtesy of the No Fluff Just Stuff symposium series which will be hosting the New England Software Symposium in March. Andrew's presentation first delved into identifying code that was too 'complex' by looking at the number of different 'paths' through a given method, The more paths a given method possesses, the tougher it is to test via a unit test. Of course, under certain circumstances a large number of paths are necessary. There are a variety of open source and commercial tools which can analyze a codebase. Andrew also discussed incorrect usages of inheritance and showed several examples in which he applied gang-of-four patterns to correctly structure the code. Of course, lowering the complexity and applying patterns may make the code easier to understand and read, but it can also affect the performance of the code. This is an important consideration in embedded or realtime applications.
Abstract
Often times, candidate code for refactoring is based upon a source file's smell, which its spotting can take time to acquire and is largely based upon subjective determinations. The proper use of code metrics, such as Cyclomatic Complexity, Fan-In, Fan-Out, and Depth of Inheritance can also facilitate the discovery of candidate code which is in need of refactoring.
For example, Cyclomatic Complexity is adept at spotting methods containing a high degree of conditional logic, which, conseqently, can be replaced with polymorphism as elaborated in Martin Fowler's seminal work, Refactoring with the Replace Conditional with Polymorphism pattern. Additionally, excessively deep hierarchy trees create problematic testing targets, which can be broken out into separate objects with Fowler's Replace Inheritance with Delegation and Collapse Hierarchy patterns. Fan-In and Fan-Out are quite effective at pinpointing brittle code, which can be refactored into a more stable state with a plethora of patterns including Extract Hiearchy and Extract Class. The knowledge of how to effectively spot smelly code and replace it with proven patterns will ultimately lead to a more stable, maintainable and elegant code base.
Speaker
Bio: Andrew Glover is the founder and CEO of Vanward Technologies, a Washington, DC, metro area company specializing in the construction of automated testing frameworks, which lower software bug counts, reduce integration and testing times, and improve overall code stability. Mr. Glover's career includes leadership in software development for such notable companies as IBM, Philips Electronics, and Proctor & Gamble and is the co-author of "Java Testing Patterns".
Links
Thanks to the No Fluff Just Stuff Symposium for flying Andrew Glover to Hartford present!
Door Prizes
Contact the Webmaster