Last post indicated a gotcha that can occur when reordering parameters in a signature. Here's one that can come up with Extract Method. Like the last example this one occurred during actual coding and it would have been prevented had I had these refactoring tools.
Say I had the following (contrived) code:
class BinaryNode { private BinaryNode left; private object value; private BinaryNode right; private int height; private Color color; public BinaryNode(BinaryNode right, object value, BinaryNode left) { //initialize fields int newHeight = 0; //logging stuff //validation stuff newHeight = max(right.height, left.height) + 1; //more stuff //figure out color height = newHeight; } }
void Initialize(..., int newHeight) { //stuff... newHeight = max(right.height, left.height) + 1; }
The different you get by using the IDE's built in support for this is that:
void Initialize(..., ref int newHeight) { ... }
When you have a huge method that you really want to make manageable it really changes things when you can just "extract, extract, extract" and haev something much more simple. After that you can do some "reorder parameters" to make things make more sense and further make your code easier to understand.