Friday, December 23, 2005

Silly extremes...

My last couple of posts have been about extremes. Rules that should be applied with a pound of salt.

Interestingly, they have had two interesting side effects. One, they make me think more about one aspect of how I'm coding. Two, they create interesting discussions with other people on my team about what the rule really means and how it has been applied.

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?