I am writing a C++ function that takes two Foo objects and adds the elements of the first into the second one, like so:
MyFunction(const Foo& a, Foo* b) {
for (int i = 0; i < a.bar_count(); i++) {
b->Bar(i) = b->HasBar(i) ? Average(a.Bar(i), b->Bar(i)) : a.Bar(i);
}
}
This is a toy example, obviously, but my point is: what should be the names of MyFunction, a and b? My first thought was something like MergeFoo but then I am not sure what to name the parameters because my best thought is something like merger and mergee which seems dumb.
What are good names for a, b, and MyFunction so that the API will be clear for users of this function?
After considering all the options, I decided the best choice is something like
AverageBarsInPlace(const Foo& new_bars, Foo* existing_bars);. I like the “InPlace” suffix from Yakk. I agree with may responses that say “don’t call itMergeunless it’s actually doing a merge”.However, my real take-away from the lack of consensus on this question is: this function has a poorly defined scope. I should break the function into more cohesive chunks, such as one function to do merging, and another to do averaging.