June 15, 2006

...Learn TDD with Codemanship

New Refuctoring - Reflectoring

If you've not already seen it, I wrote a little piece for Waterfall2006 on refuctoring - the process of making well-designed code unmaintainable by anyone but yourself (therefore securing your job for the long term) through a series of small, reversible "refuctorings". Refuctoring is a key discipline in mortgage-driven development. The example refuctorings are over the top, of course, but all based on real code I've seen in the last 14 years. Another refuctoring I've seen used to devestating effect involves the use of reflection to make code as unreadable as possible.

I call this reflectoring. Here's a simple .NET example. Take some very simple C# code, like a method call, and then, for no readily apparant reason whatsoever, replace it with the equivalent code using .NET reflection...

int score = cricketMatch.CalculateScore();

REFUCTORED! ----------------->

Type type = footballMatch.GetType();

object returnValue = type.InvokeMember("CalculateScore", BindingFlags.Default | BindingFlags.InvokeMethod, null, cricketMatch, null);

int score = (int) returnValue;

A similar effect can be achieved using Mock Objects to make unit tests much more difficult to follow. This is another new refuctoring, which I call making a mockery of your code :-)
Posted 15 years, 1 month ago on June 15, 2006