Thursday, July 12, 2007

YAGNI - The No Frills Design Principle

Occam’s Razor – YAGNI is based on an ancient principle referred to as Occam’s Razor – “Entities should not be multiplied beyond necessity” which is commonly paraphrased as “All things being equal, the simplest solution tends to be the best one”.

What is YAGNI? – YAGNI, short for 'You Ain't Gonna Need It', suggests that one should not add functionality until it is necessary –

  1. Keep the system uncluttered with extra stuff you guess will be used later. Only 10% of that extra stuff will ever get used, so you are wasting 90% of your time.
  2. A simple design always takes less time to finish than a complex one. So always do the simplest thing that could possibly work.
  3. If you find something that is complex replace it with something simple. It's always faster and cheaper to replace complex code now, before you waste a lot more time on it.
  4. Keep things as simple as possible as long as possible by never adding functionality before it is scheduled.

Advantages of YAGNI

  1. It is a defense against pretty much every programmer/architect’s desire to find general solutions, even when we are being paid to do something specific.
  2. It protects us from wasting time, and protects us from over-architecting.

Gold-Plating – This term refers to a family of classic mistakes related to the way a product is defined that the YAGNI design principle automatically prevents –

  1. Requirements gold-plating – Some projects have more requirements than they need right from the beginning. Performance is stated as a requirement more often than it needs to be, and that can unnecessarily lengthen a software schedule. Users tend to be less interested in complex features than marketing and development are, and complex features add disproportionately to a development schedule.
  2. Feature creep – Even if you're successful at avoiding requirements gold-plating, the average project experiences about a 25-percent change in requirement over its lifetime (Jones 1994). Such a change can produce at least a 25-percent addition to the software schedule, which can be fatal to a rapid development project.
  3. Developer gold-plating – Developers are fascinated by new technology and are sometimes anxious to try out new features of their language or environment or to create their own implementation of a slick feature they saw in another product--whether or not it's required in their product. The effort required to design, implement, test, document, and support features that are not required lengthens the schedule.

Other disadvantages of not using YAGNI – Software engineering experts [Kent Beck, Martin Fowler, Ron Jeffries, etc] who advocate the YAGNI approach have found that the temptation to write code that is not necessary at the moment, but might be in the future, has the following disadvantages:

  1. The time spent is taken from adding, testing or improving necessary functionality. The new features must be debugged, documented, and supported.
  2. Any new feature imposes constraints on what can be done in the future, so an unnecessary feature now may prevent implementing a necessary feature later.
  3. Until the feature is actually needed it is difficult to fully define what it should do and to test it. If the new feature is not properly defined and tested, the unnecessary feature may not work right, even if it eventually is needed.
  4. It leads to code bloat; the software becomes larger and more complicated.
  5. Unless there are specifications and some kind of revision control, the feature may not be known to programmers who could make use of it.
    Adding the new feature may suggest other new features. If these new features are implemented as well, this may result in a snowball effect.

References – The above document contains extracts from the following -

  1. http://extremeprogramming.org/rules/simple.html
  2. http://extremeprogramming.org/rules/early.html
  3. http://extremeprogramming.org/stories/simple.html
  4. http://en.wikipedia.org/wiki/Occam
  5. http://stevemcconnell.com/rdenum.htm (Points 28-30)
  6. http://fishbowl.pastiche.org/2004/03/02/defending_yagni
  7. http://c2.com/xp/YouArentGonnaNeedIt.html

No comments: