Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I often find that using test driven development helps guide me when faced with these questions.</p> <ul> <li><em>When is a simple approach sufficient?</em> It is always sufficient to use the simplest approach to get the next test to pass. But knowing when/how to refactor is the real art form. </li> <li><em>What is the minimum size of a piece of software that justifies the use of the GoF patterns?</em> A rule of thumb I once read is that when you code something once, fine, when you duplicate that code somewhere a second time, make a note and move on. When you find a need for the same code a third time, it's time to refactor to remove duplication and simplify, and often that involves moving to a design pattern. </li> <li><em>When to refactor from simple-minded to GoF?</em> I like what @anopres said - it's time when you feel the pain of not having the design pattern in place. The pain (or code "smell") may manifest itself in several ways. Code duplication is the most obvious. Refactoring books like Fowler's <a href="http://rads.stackoverflow.com/amzn/click/0201485672" rel="noreferrer">Refactoring</a> or Kerievsky's <a href="http://rads.stackoverflow.com/amzn/click/0321213351" rel="noreferrer">Refactoring to Patterns</a> list many such pain points/code stenches. </li> <li><em>Can this [refactoring] be done in a sensible way?</em> The trick to refactoring is to have a suite of unit tests in place which you have confidence in, and then to refactor without causing any of those tests to fail. Refactoring, by definition, does not change the functionality of your code. Therefore, if your tests continue to pass, you can have a pretty good feeling that you didn't break anything. Although it can be difficult, I actually enjoy this part of TDD, it's almost like a game to make changes without breaking any tests.</li> </ul> <p>In summary, I would say that TDD helps guide me to write the code that is sufficient at the time, and perhaps more importantly helps me to make the changes later when inevitably requirements change, more functionality is required, etc. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload