Python Rocks! and other rants
Weblog of Kent S Johnson

2004-04-30 23:14:08

Simplicity Rules

One of the qualities that distinguishes code-and-fix hacking from software craftsmanship is a different idea of what "done" means.

If you are hacking [1], the primary goal is to create something that seems to work. If you are a craftsman and you want to create something that may endure, something you can be proud of, that is only part of the story. The XP Simplicity Rules express the difference very well. According to these rules, simple code:

  • Runs all the tests.
  • Expresses every idea that we need to express.
  • Says everything Once and Only Once.
  • Has no superfluous parts.

Runs all the tests

In other words, it works. More than that, it demonstrably works because there are tests and they pass. This is a higher bar than just "working".

Expresses every idea that we need to express

This encompasses many aspects of good coding hygiene: The architecture is suited to the job it does. Classes have clear responsibilities. Methods and varibles are named appropriately. Comments explain the tricky parts.

BTW a good rule about comments is this: Whenever you think you need a comment to explain something, consider putting the code that would follow the comment into a subroutine with a good name. That way the comment may not be needed and the code will read more clearly.

Says everything Once and Only Once

I have written about this in this essay - I won't repeat myself here :-).

Has no superfluous parts

Take out the cruft! If it's not needed to fulfill the current requirements, get rid of it! Don't worry about keeping stuff you might need later, you can always dig it out of source-code control and put it back in. Comment it out for a while if you must, but after a while rip out the comments.

"Perfection, then, is finally achieved, not when there is nothing left to add, but when there is nothing left to take away. " --Antoine de Saint Exupery

[1]"Hacking" has many meanings. I mean no offense to classic hackers such as Eric Raymond.
© Kent S Johnson Creative Commons License

Comments about life, the universe and Python, from the imagination of Kent S Johnson.

Weblog home

All By Date

All By Category