Advice from an Elegant Coder

by Lord Cod3n 26. September 2008 06:40

Here is some advice/comments from Tony Rasa who can be found at: http://elegantcode.com/about/tony-rasa/.  I misused the term refactoring.  I kind of realized that after it was pointed out.  Here is what Tony had to say:

 

Glad that Red/Green/Refactoring is starting to make sense for you.

You might want to look at the definition of 'refactoring' a little more closely however - "To re-write existing source code in order to improve its readability or structure without affecting its meaning or behavior" - so "refactoring" to add in the implementation of your test body is not truly 'refactoring,' you're still getting to green.

refactoring is realizing that your implementation makes sense as its own method, so you move the code out to its own private method and replace that space with a call to your newly minted method -- no change in behavior, the test still passes, but you've improved the structure of the code.

Tony

 

My response was along the lines of when do I write the real code ?  His response to that question was as follows:"

you can think of the 'not compiling' step as an "extra red," where you figure out what you'd like the usage to look like. Sometimes this is easy to skip.

Then you have a

'compiles-but-throws-notImplementedException-or-otherwise-returns-the-wrong-values'

step, still red. the test fails because you haven't implemented it yet.

Then you implement 'just enough' to pass the test, where 'just enough'

is sort of tricky to figure out but at first err on the side of "as little code as possible." this is where you make the code work for real.

and now you're green.

now, look at the code you wrote, and consider the next place you need to go with the code & tests - is it in the right direction? if theres something that isn't, refactor (changing structure but not behavior) - and you can re-run the tests to make sure you don't break anything while you're refactoring. (thats the value of the tests - they remove some of the risk)

now that you've got this test case done, move on to the next test (red) etc etc.

Excellent advice.  I am going to chew on this a bit while I take a break.  I will post up more later.  Thanks Tony for taking the time to respond.  You have been very helpful is correcting my off path wanderings, and thus probably saved me a ton of reading.

 

Code Happy

Bill

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

William Moore is the lead Software Architect and Technologist for Coden Enterprises. He has more than a decade of software development experience primarily Microsoft Platforms.  William enjoys the full gamit of coding everything from the UI down to the database.

Most comments

Page List