Judging Code Simplicity? Fit It Through the TUBE!

by zachary.spencer on March 4, 2010

We coders have all kinds of definitions of simple code. To some, simple code is code they understand and read easily. Others believe simple code follows the coolest, most appropriate design pattern. Some crazy person may even say that simple code has the fewest characters. To attempt to settle that debate, Extreme Programming offers four subjective qualities of simple code: testability, browsability, understandability, and explainabilty.

To make these qualities easier to remember I suggest using the mnemonic TUBE.

Testable

  • Can automated test cases be written for each piece of functionality?
  • To pass the “test of testability” you should have tests which exercise both positive and negative functionality.

Understandable

  • Bob Martin puts forward some criteria in his book: Clean Code. When you look at a function, does it do exactly what you expect it to do? Is it immediately obvious what the code does?

Browsable

  • Can the code be browsed in an IDE? Can someone who didn’t write the code find pieces of functionality easy?

Explainable

  • I’m pretty sure the reason this is here twice is it’s because it’s so important. Can a different developer tell you what the code does?

If you code passes these four tests, congratulations! You just made your code fit in the tube. Remember: If the tube fits, make commits!

Special thanks to Abby Fichtner (@hackerchick) and Thomas Schultz (@daspecster) for providing peer review!

Leave a Comment

Powered by WP Hashcash

Previous post:

Next post: