there is something that\'s bugging me.
In a non-threaded program, is it better to have local static variables(inside methods) or static class members?
In thi
I usually try to limit the scope of variables as much as possible, as long as it doesn't become weird or tedious.
If you have 1000 lines of code in class C
, of them 100 lines of code in the function foo
, any change you do to bar
(for example, changing the name or type) requires going over 100 lines of code to make sure the change is OK. If you had bar
a static class member, you might have to go over 1000 lines of code, just to make sure bar
is not used there. This would be a waste of time.
If you think you might need bar
in another function foo2
(for example, when counting call count for foo
and foo2
together), you might want to make bar
a static class member.