Thursday, December 22, 2005

Another piece of the "deeply nested if" smell...

I was doing a little refactoring with Srini today and made a mental note of something to look for. When I see multiple nested ifs in a method, it seems to indicate a problem with responsibility. Usually, you are asking one object one thing, another object another thing, then even another object a third thing and then finally you operated on that third thing.

In this code it looked like you were reaching into the guts of other objects and playing with them. Once you reorganized the method, it was easy to move the ifs and their actions into different objects and the code began to make sense.

I'm going to play with a rule that says "I can only perform ifs on the results local methods/variables".

Lets see what happens. Anyone want to play with me?

0 Comments:

Post a Comment

<< Home