I've just done a code review where I came across a method like this:
private void FindMinAndMax(double[] values)
{
// Some algorithm that results in two class vars being assigned:
_min = ...
_max = ...
}
(After returning, the calling code utilises these two values in various calculations; the calling code then calls other private methods that utilise these two values).
Personally I don't like this method as you would never know that these vars are being set just from looking at the calling code (in fact the programmer had even put a comment next to the method call to say "This sets _min and _max", reinforcing my opinion!). My recommendation was to either use "out" parameters, or return a tuple containing the two values.
It got me wondering whether there is any guidance/pattern/best practice when it comes to methods assigning or modifying class-level variables?