The Law of Parsimony

for RuBoard

In philosophy, the law of parsimony (a.k.a., Ockham's razor ) states that the simplest of two or more competing theories is preferred to more complex ones. To the software designer, this means that the simplest approach to providing the required functionality is usually the best. Creating unnecessary complexities and obfuscation does not make one a better coder . In fact, it's exactly the opposite . From my experience, the best programmers, regardless of language, are those with a gift for being able to create solutions to intricate problems from simple inventions and techniques. The best code has a sense of elegance to it that derives from its simplicity. It is better code because it is simpler code.

In his book Refactoring: Improving the Design of Existing Code , Martin Fowler had this to say on the subject: "You build the simplest thing that can possibly work." [3] I agree with this statement to a point. A concern I have is that one man's simple is another man's complex. Sizing up the complexity of a proposed solution can be a completely subjective task. What's obvious and intuitive to you may confuse me to no end. Another concern I have is that oversimplifying a problem or failing to consider the long- term ramifications of the design decisions you make can cause problems down the road. The law of parsimony should never be used as an excuse to abandon forethought and the grasp of the overall picture.

[3] Fowler, Martin. Refactoring:Improving the Design of Existing Code . Reading, MA:Addison-Wesley, 1999. Page 68.

You'll see the law of parsimony in evidence in many of the idioms and design patterns covered in this chapter. One of the most productive things you can do to write better code and to clean up existing code is to remove unnecessary complexity. Doing so helps you not just now, but six months from now when you or someone else must work on the code again. It is an investment in the future health of your code. If a loop to execute a block of code a given number of times runs forward in some places and backward in othersfor no apparent reasonthe code contains needless complexity. People reading through it are forced to note that, even though the code looks different, it actually performs the same function as another, more straightforward code block. A prime tenet of good software design is the elimination of differences that make no differencevariations without a purposeso that what remains are those worth noting.

And, although there may be many ways to do something, generally the simplest, most straightforward approach is best. We have enough complex software engineering problems to solve without creating them for ourselves through poor coding practices.

for RuBoard


The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML
The Guru[ap]s Guide to SQL Server[tm] Stored Procedures, XML, and HTML
ISBN: 201700468
EAN: N/A
Year: 2005
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net