Implementation Patterns: Write Software to be read as a Story!

MOTIVATION


The idea for this article came from reading a book named "Implementation Patterns". The author Kent Beck is a renowned programmer. One of Kent's observations is to design and write software with economics in mind, as software begins to play a bigger role in the corporate food chain. He points out, "Software should be designed to reduce cost".

For many organizations, software has become a key building block in their business Infrastructure. Recently, I came across a company who are in the direct mail business, the fliers that you get in your mail box advertising stuff. Now, they are exposing their entire infrastructure as an internet service for clients to order personalized US postal mail over the Internet.

In the new distributed world of computing, infrastructures that were traditionally not exposed to the outside world are suddenly finding themselves exposed to the naked call of far flung users through web service APIs.

REDUCING COST


As businesses are key drivers of the software, it interests them to understand and manage the cost.

If we care to represent the software cost into an equation,

Cost_Total = Cost_Develop + Cost_Maintain

Now, the second part of our cost equation can be rewritten as,

Cost_Maintain = Cost_Understand + Cost_Change + Cost_Test + Cost_Deploy

If your goal is to reduce and control the cost of software, which one of the above activities interests you the most and is likely to give the best bang for the buck?

For e.g., Would you spend more time upfront software design, hoping a better design saves you cost in the future, asks Kent? He points out, a dollar today is worth more than it is tomorrow. Hence, the suggests a deferrance of costs to a later time, where that is possible.

Offcourse, there is a saying, "Build to the requirements known at the end of the project and not the ones at beginning of a project." Agile methods anyone?

READABILITY


It is interesting to see there is a cost to understand someone else's code. Kent points out, it is not unusual for developers to think of computers as the ultimate consumers of their code and bother less about readability. Instead, he suggests a mindset that thinks that every line of code you write is for the consumption of a human being. Now, that changes our outlook. Doesn't it. That someone that reads that code in some distant tomorrow could be even you.

METAPHOR: CODING A STORY


Have you ever thought of your software as a story to be read by someone?

Kent goes on to suggest practical ideas to economize on the cost of your code. He and Ward Cunningham, the inventor of CRC cards, took a well written program and rewrote it, completely. They said, whenever, they felt a part of the program needed more comments or explanation, they simply rewrote it to make it more readable. They were pleased with their end result.

WHAT IS IN A NAME?


Kent suggests a metaphorical process and attention to details such as the naming of the classes in your software design. When you choose a name that immediately suggests to the reader the purpose of the class, you have done your job well.

As a simple example, here is a software service that handles emails and has an interface named as IMessages. The APIs in this interface are, Send, Get, Delete

The point here is, choose names whose meaning aptly represents the context in which your class operates and hence becomes obvious to the reader. Thus, you have reduced the cost of understanding your software and hence saved monies.

MORE EXAMPLES


Well. What about a more complex example, you ask.

Recently, I was tasked with prototyping an email client. I had to find a name for a class that establishes a TCP session with the server and does the donkey work of transporting emails back and forth. Initially, I named it as INetManager, 'cause I figured it manages the network. Then I renamed it as INetConnect 'cause it establishes a connection to the server. Finally, I renamed it as IMailTransport. The fact is this class sets up the transport that sends and receives mail back and forth from the server. The name represents just that. Now, I am off to naming my class that handles POP3 protocol and am still scratching my head to come up with an appropriate name.

0 comments:

Post a Comment