Deep Simplicity

Code Naked

  • Homepage
  • About
  • Contact

Dec 29: Deep Simplicity

So, I am a huge fan of ThoughtWorks. I really think that the crew over there are on the edge of everything I strive to be as a good developer. Many of the software development best practices are pioneered by people like Martin Fowler that work there. I recently picked up the book The ThoughtWorks Anthology and was impressed by many of the articles. Probably my favorite was the the one written by Jeff Bay titled "Object Calisthenics." He talks about 9 steps to better software design through a concept called "Deep Simplicity", and I like them. A lot.

1. Use only one level of indentation per method
2. Don't use the else keyword
3. Wrap all primitives and strings
4. Use only one dot (-> in PHP) 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/properties

Holy cow, I bet some of you are freaking out already! Don't use getters or setters?!?!?! Don't use more than two instance variables per class? Impossible! Although I am not sure you have to comply to these rules 100%, I think keeping them in mind when developing is going to help you write better code.

I recently posed the following chunk of code to a co-worker:
I then asked him to "make it better". He ended up with the same basic loop just with less lines. I then showed him the code that I had written for the same chunk of code.
Now, as I often say, there is no such thing as "the right way" to solve a problem. I do feel that the solution I came up with is better, the improvements being garnered through applying rule #1: one level of indentation. In fact, I only indented once in the check to see if the $limit value was valid. Everything else is at the default indentation style for class methods. What we got as a result was an improved API that allows a consumer to get all widgets, all widgets that are in stock or a limited number of widgets that are in stock, which was the original requirement. We also get a completely reusable filter object that can accept a list of anything as long as the objects in the list implement the isInStock() method.

Next post will be about rule #2: Don't use the else keyword.
Posted by Matthew Purdon in Software Development Comments: (0) Trackbacks: (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

No comments


Add Comment

Standard emoticons like :-) and ;-) are converted to images.
 
 

Subscribe

Archives

  • March 2010 (0)
  • February 2010 (1)
  • January 2010 (4)
  • December 2009 (6)
  • Recent...
  • Older...

Categories

  • XML Technology
  • XML Databases
  • XML MySQL
  • XML Software Development
  • XML Being a Contractor
  • XML Client Side
  • XML PHP
  • XML State of the Art


All categories

Blog Administration

Open login screen

Recommended Reading

Amazon.com: The Nomadic Developer: Surviving and Thriving in the World of Technology Consulting (9780321606396): Aaron Erickson: Books
Amazon.com: Domain-Driven Design: Tackling Complexity in the Heart of Software (0076092019565): Eric Evans: Books
Amazon.com: Patterns of Enterprise Application Architecture (0076092019909): Martin Fowler: Books
Amazon.com: Refactoring: Improving the Design of Existing Code (9780201485677): Martin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts: Books

Feedburner

Numeric Feedburner ID Required!




 

Layout by Andreas Viklund | Serendipity template by Carl