Geeks With Blogs

Shelfari: Book reviews on your book blog

.net alternatives by Michel Grootjans

This is a topic that is near and dear to me. Readability is about being able to understand the code. Maybe the word should be “Understandability”, but that word suffers of the exact same thing it describes ;-)

Anyway, compare these two lines, and tell me what line you understand fastest:

   1:  startDate = new DateTime(2008, 5, 15);
   2:  startDate = 15.May(2008);


This might not seem much, but to me line 2 clearly states the intent of the code, whereas line 1 makes me think. I don’t want to think about how the code is implemented, I want the code to explain what it does, even why it does it.

Another one of these causes of confusion is the lambda extension from RhinoMocks x.Stub(x => x.DoStuff())… Every time I introduce mocking to a new team, I have a lot of explaining to do around the ‘Stub’ Extension. I recently introduced a change to the team for this one particular call. Compare these two:

   1:  userMapper.Stub(m => m.Map(user)).Return(viewUserDto);
   2:  When(userMapper).IsToldTo(m => m.Map(user)).Return(viewUserDto);


Again, this exercise might seem unnecessary, as experienced developers will instantly understand this. In my experience however, all developers tend to understand this kind of code without much effort.

Just my €0.02

Posted on Tuesday, May 19, 2009 3:17 PM .net | Back to top

Comments on this post: It’s all about readability

# re: It’s all about readability
Requesting Gravatar...
I am completely with you!
Readability established by well designed api can help learning and understanding an api so much.
Your first example is really great. I think I have to do some training for creativity!
Left by Dirk Rodermund on May 20, 2009 7:30 AM

Your comment:
 (will show your gravatar)

Copyright © Michel Grootjans | Powered by: