Code Smells

I'm a big fan of the concept of "code smells" - the notion that you can subconsciously evaluate the elegance/correctness of a code by how it "smells" to you. Similar to "beauty" in mathematics or physics, I suppose.

Sean Corfield, at An Architect's View, just posted an overview of Josh Kerievsky's session at SD West.

A code smell is when you sense something is not really right and the code can be improved by refactoring. He defined "super" code as having the following 4 S's: "Safe, Succinct, Straightforward, Simple". Code smells when it violates one or more of those principles. He noted that sometimes comments can be considered deodorant for "smelly code" - better to refactor (and fix the problem) than simply add comments (to document the problem)!

For example, when touring the Pachyderm codebase, you can tell who wrote it by the smell. King's code smells like a tropical beach. Clean. Breezy. A place you want to spend the day hanging out.

My code, on the other hand, tends more toward a downtown back alley - functional, not the cleanest place to be, not someplace you want to spend a lot of time, and often smelling oddly of fish.

comments powered by Disqus