Question

On page 242 of Code Complete 2, Steve McConnell touts The Principle of Proximity.
Put simply, Mr. McConnell advises programmers to keep related actions together.

In my case, the applicable emphasis is:

  • It's important to initialize and set variables (and objects) close to where they are being used.

It's usually easy to abide by 'The Principle of Proximity' when you're working within a single code block or method body; but what if you're working with legacy code and an object at the top of the stack is set or mutated deep within the stack? To make things more complicated, what if that object is set, mutated, or referenced multiple times within the stack?

So here's my question:

What is the Most Expedient Way to Make Legacy Code Conform to 'The Principle of Proximity'?

Incidentally, I'm working with Visual Studio 2010 and Resharper 5.
Are there any IDE tricks that could help me out?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top