This workshop was for heavy coders; those who are often called-upon to clean-up, speed-up and clarify code.
Randy Coulman delivered a mob-programming-style workshop, in consideration of the diversity of the audience’s programming languages. He used a simple inventory system as a basis for the technique of refactoring (reorganizing | rewriting | rewording | renaming) elements of existing code to achieve the desired result.
The exercises brought into play the following laws, methods and advice:
- Kent Beck’s Advice: For each desired change, make the change easy to understand. (WARNING: This may be harder to do than expected.)
- Make disciplined changes.
- Change structure without changing behavior.
- Martin Fowler’s book entitled, Refactoring: Improving the Design of Existing Code
- Intuition: A.K.A. “Code Smell”; if it doesn’t feel right, it may not be right.
- Michael Feathers’ book entitled, Working Effectively With Legacy Code
- The (Boy | Girl) Scouting Rule: Leave the campground cleaner than you found it.
- Work in baby steps: Lots of tiny, safe refactorings add up to big changes.
- Don’t boil the ocean: Stay focused on your task.
- Use an IDE that supports refactoring, such as RubyMine
- Demorgan’s Laws, which deal with boolean logic.
- Make the code look like it would have looked if the feature you add had always been there.
When to refactor? As an ongoing part of your workflow; Test-Driven Development (TDD).
Why refactor? To make the code reflect your current understanding of the system.
Randy brought his decades-long experience to bear as he moved through an example of code that had been modified multiple times to clean it up and refactor the logic to make it easier to understand—and maintain.
Thanks to Randy for volunteering his time to educate us about how to make cleaner—and faster—code!
For more information and additional links, please navigate to Randy’s Slides on SpeakerDeck.
NOTE: This was the last Tech Workshop of this season. We will be on hiatus until the Second Thursday of October. Upcoming topics include Data Visualization (probably a TechCombo; Tech Talk and Tech Workshop during the same week); Trend Spotting; Pitfalls of Launching a Tech Business; and Nitrous and other Open Source IDEs.
I’d like to thank the following individuals for making themselves available via email, phone and in person, to provide support for Tech Talks and Tech Workshops at SOU.
- Sherry Ettlich, Director of STEM, for her enthusiastic support, and loan of her assistants, as necessary.
- Pete Nordquist, C.S. Department Chair, for his encouragement and promotion of these tech events.
- Candy Barnhill, Assistant to the Director of STEM, for her courteous, timely and perfectly-executed adjunct services (not part of her job description): providing parking permits, scheduling conference rooms, and arranging for FREE PIZZA at the Tech Talks!
- Michelle Wills, Assistant to the Director of STEM, for helping out when Candy is unavailable.
- Bob Sexton, Computer Lab Manager, and his staff for being ready, willing and extremely able to assist with all manner of hardware, software, network and connectivity issues at a moment’s notice.