Randals Rule

RandalsRule is a debugging rule that holds true so often it must be a pattern.

Most bugs are fixed just by deleting code. (i.e. not adding any)

Origin is from my boss who told me it years ago and I laughed, then years passed and it's no longer funny, just ironic.

Specific examples:

Really this is one of those rules that seems insane until you've heard it, then you start to notice it everywhere.

-- LayneThomas


Addendums:

I just revisited this pattern in a project where I fixed a redraw problem by deleting all the HideWindow? functions except one(no chokepoint, just call removals). An AhHa moment happened when I realized this is just OnceAndOnlyOnce from a different angle. The bug was caused by having excessive (and redundant) code - most certainly a CodeSmell, and in this case it developed into a legitimate bug.

It seems RandalsRule is a pattern with the context of when violating OnceAndOnlyOnce causes a bug. Seems so obvious now. . .

As a corollary; if you find that RandalsRule doesn't hold for your project or organization, you might be religiously applying OnceAndOnlyOnce already.

Unless refactoring a legacy system where you should apply it liberally. . .


Another addendum:

This rule seems to apply when writing new code as well. A complicated if, else, elseif block can sometimes be reduced to just one or two lines.

Trite Example:

if (default) {

 a=2;
 b=3;
}

else {

 a=2;
 b=5;
}

could be reduced to:

a=2; b=3;

if (!default) {

 a=2;
 b=5;
}

or even more extreme as:

a=2; b=3; if (!default) b=5;

This is admittedly a trite example, but hopefully makes the point that RandalsRule is an example of the OnceAndOnlyOnce pattern.


EditText of this page (last edited December 28, 2011) or FindPage with title or text search