When is it good form to push a local variable to a function/method as a parameter, rather than using a class variable in place of the function/method variable.
For i
It shouldn't be about what gives more or less code or what takes more effort to type. It is about what is more logical within the context of that class and function. Keeping things isolated from each other like you do is in general a good thing but don't over do it. When it is clear from the purpose of a function that it should be working on a value contained in a class var it should do so and not receive the value through a parameter.
The only answer out of the blue, for a any generic case is: it depends on your specific case. Data members, static members and function arguments all serve different purposes. Of course, there are some key tips we can give for what types of signs you should look for choosing one or the other.
Typical cases:
There are some common symptoms of bad choice.
Consider the following questions:
I'm under the impression that you and your co-worker are in a simple misunderstanding of the nature of this parameter. Make sure you clearly understand your co-worker's arguments and make yourself clear. Try to rephrase what it is that you're trying to say.
I look at it in terms of dependency, i.e. who is dependent on the variable (in your case var
), is it a method or a class?
For e.g. JavaBeans have class variables that are dependent by the class, so if the class needs these variables then DoSomething()
is best.
Alternatively, if you class doesn't care about var
and doesn't need it anywhere else, and only DoSomething()
requires var
, then DoSomething(int var)
is essential.