.net alternatives

by Michel Grootjans
posts - 50, comments - 84, trackbacks - 1

My Links

News

Shelfari: Book reviews on your book blog

Twitter












Archives

Post Categories

It’s all about readability

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

Print | posted on Tuesday, May 19, 2009 3:17 PM | Filed Under [ .net ]

Feedback

Gravatar

# re: It’s all about readability

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!
Regards,
Dirk
5/20/2009 7:30 AM | Dirk Rodermund
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: