I usually try to limit the scope of variables as much as possible, unless it becomes weird or tedious.
If you have 1000 lines of code in class C
, including 100 lines of code in the foo
function, any change you make to bar
(for example, changing a name or type) requires going over 100 lines of code to make sure that the changes are okay. If you have bar
static member of the class, you may have to move more than 1000 lines of code to make sure that bar
is not used there. It will be a waste of time.
If you think you might need bar
in another foo2
function (for example, when counting the number of calls for foo
and foo2
together), you can make bar
static member of the class.
anatolyg
source share