Not a programming question,
per se , but also seemed too close to programming to go in the lounge.
Our code is littered with methods like this:
public int fetchStuff(int param1, int param2, out int returnA, out string returnB...)
Where this method performs some kind of computation based on params 1 & 2 (typically a db inquiry, but doesn't have to be).
This isn't about the camel casing of the method name. While that is wrong (and also indicative of the quality of code produced by people who do this--they can't get the little stuff right, how can they get the big stuff right?), I'm questioning the use of out variables. It seems so non-OO. Take some inputs and produce a result or throw an exception.
Also, the use of out variables means that the signature has to change when new data are added to the results. Sure, we can use overloads to have the old signature call the new method and throw away the new data to reduce the affect on consumers who don't care about new data, but that seems clumsy. (As opposed to returning an object, where we can add new information and consumers can use it or not, at their discretion, but signatures don't change).
OTOH, Microsoft themselves use out variables in the TryParse-type methods, so maybe it's something that really bothers me, but shouldn't.
What I have tried:
Depending on the situation and time constraints, I'll usually refactor these to return a StuffContainer object, then refactor the callers to reference that. Just not sure how necessary that is.
(Necessary not the right word; obviously there's no
need to do this. I can't think of the right word though--not desirable, as it clearly is that.)