2 ms·
> I agree with you here and tend to rather, if possible, deduplicate subsystems or sub-functions of similar looking/identical code and keep the duplicate public
by joshstrange 3y ago
> I agree with you here and tend to rather, if possible, deduplicate subsystems or sub-functions of similar looking/identical code and keep the duplicate public surfaces.
Completely agree, take the small parts that are standalone/discrete and abstract them. I greatly prefer something like
function1() {
commonCode1();
commonCode2();
commonCode4();
}
function2() {
commonCode2();
commonCode3();
commonCode4();
}
Over something like (assume I've inlined the commonCodeX logic):
functionCommon(branchingParam) {
if(branchingParam) {
commonCode1();
}
commonCode2();
if(!branchingParam) {
commonCode3();
}
commonCode4();
}