I just had a moment of clarity about refactoring and encapsulation. Its a simple truth and is one of the basic tenants of the concept and I had kind of forgotten about it.
By putting variables inside functions you can make them private.
Why is this useful. Well consider that you want to CHANGE one of those functions. Change ? who would EVER want to do that ?
If it is declared as a private function you KNOW FOR SURE that no-one else is using it and therefore that YOU CANNOT BREAK ANY OTHER CLASSES.
Therefore it is COMPLETELY SAFE TO REFACTOR.
great isnt it!
Such a thing you take for granted and yet when you work with a different language domain it suddenly reminds you of all the good things about OO.