Tag Archives: Refactoring

Refactoring Reflections

In Don’t Make Me Think, Steve Krug presents the premise that the better a web site’s usability, the more brain cycles the visitor is able to focus on the substance (or intention) of the site. Said another way, the less brain cycles a visitor spends figuring out how a site works (e.g. how to navigate around), the more brain cycles he has available to concentrate on site’s substance. Don’t Make Me Think’s goal is to help the reader refine his web site’s usability to the point that visitors don’t need to think about how to use the site and so can focus all their attention on the information the site was built to convey.

While working through a recent refactoring project, it occurred to me that Don’t Make Me Think’s premise closely parallels one of the main motivations behind refactoring. The better the code base’s quality, the more mental energy the code reader can focus on the intention of the program. The less brain cycles a developer spends figuring out how a bit of code does what it does, the more brain cycles he can spend focusing on what the code does. Continue reading

SQL Refactoring – Comparing Result Sets with EXCEPT

I often refactor SQL, cleaning up convoluted statements using language features such as views, common table expressions and nested joins. It’s one thing to rework a gnarly query into something legible; it’s another thing to verify that the rewritten query returns the same data as the original.

The starting point for verification is comparing the result sets returned by the old and new queries. I’ve recently found Microsoft T-SQL’s EXCEPT operator quite handy for this purpose. Continue reading