I’m having an argument with my colleague. When overloading two methods, is it considered bad practice for the one with more parameters to call the one with fewer parameters?
For example:
method (P p1, P p2, P p3) {
<do something with p1 and p2 => newP>;
method (newP, p3);
}
method (P p1, P p2) {
....
}
Overload chaining like this is a common practice (in particular with constructors) – I wouldn’t call it bad, though it can be abused like most language features.
As far as it reduces code duplication, it is a good practice. Most of the time, I find it is also more readable.
I would say that using this technique is a matter of personal opinion and style rather than absolute good or bad practice.