Being Cellfish

Stuff I wished I've found in some blog (and sometimes did)

Object Calisthenics: First contact

Change of Address
This blog has moved to blog.cellfish.se.

Object Calisthenics: First contact

  • Comments 1

A few weeks ago I was introduced the the object calisthenics described by Jeff Bay in the book The ThoughtWorks Anthology. The object calisthenics is a way to practice writing object oriented code. The nine rules of are not intended to be used in your every day work. The rules are intended to be used on a small problem such as a coding Kata. The idea is that by applying these strict rules on a small problem you'll learn to write better code.

So I decided to try this on the MineSweeper Kata. In the beginning I decided to try to conform to the rules all the time, but pretty soon I changed my mind and wrote a working solution and then started to refactored to conform to the rules. I think this was a mistake. Some design decisions turned out to require very big refactorings when conforming to the rules and I actually never got all the way. But this doesn't mean I didn't learn anything. First of all I think I experienced a variant of you can't test in quality, you have to build it in from the start. I should have stuck with the initial strategy and make sure the code followed the rules all the time. I also learned that classes that I felt were really small and doing only one thing actually could be split up when I had to in order to conform to the rules. Reminds me of when people thought atoms were the smallest building blocks of the universe and then it turned out to be something smaller...

So all in all I think doing a coding Kata while applying the object calisthenics rules will improve my ability to write object oriented code. And it will be interesting to see how it works out in a coding dojo. By now you're probably wondering what the nine rules are. The rules are:

  1. Use one level of indentation per method
  2. Don't use the else keyword
  3. Wrap all primitives and strings
  4. Use only one dot per line
  5. Don't abbreviate
  6. Keep all entities small
  7. Don't use any classes with more than two instance variables
  8. Use first class collections
  9. Don't use any getters, setters or properties

I'll go into more detail of these nine rules over the next few days.

  • I recently talk to a friend who was migrating a large/complex system he wrote in J++ (ten years ago)

Page 1 of 1 (1 items)