DO_F() {
A;
B;
C;
D;
B;
C;
D;
E;
F;
A;
B;
C;
D;
G;
H;
I;
J;
A;
B;
C;
H;
I;
// a bunch more
}
So I suggested, "hey perhaps you should break this into functions" and got back: DO_F() {
A;
B;
C;
D;
B;
C;
D;
E;
F;
A;
state.a = a;
state.b = b;
// ... for other state
return DO_F2(state)
}
DO_F2(state);
B;
C;
D;
G;
H;
I;
state.a = a;
//...
return DO_F3(state);
}
DO_F3();
J;
A;
B;
C;
G;
H;
I;
// a bunch more
}
When I suggested blocks such as B; C; D; or G; H; I; could be functions, and perhaps a loop could be useful too, the guy looked at me like I was trying to do voodoo and got really defensive about how that couldn't possibly work.I think that is what the OP meant by bulldozer code...
Given the choice between reusability and readability I'd say that readability should usually win (although it is a false choice).
Chunking for the sake of itself doesn't seem like a viable strategy to me.
"These two blocks of code do something different"
Thats what is normally called a method. If it's only for one class then by all means make it private and name it well, so the caller remains readable.
Whitespace and comments can suggest that some pieces of code don't interact that much, but chunking into functions lets the compiler prove it.
I also refactor for the sake of readability (and urge my co-workers to do the same). Of course, this might mean I'm a bad programmer and I shouldn't ever get 6 levels deep in logic in the first place...
I feel like this might give people the wrong idea. Surely some amount of cohesion is desirable. Also, I'm not quite sure how one "gives the appearance of refactoring" without actually refactoring. Whether it's useful or not may enter into it, but I would usually consider the breaking out of chunks into subroutines refactoring.