I would like to have some easy way to support me while rewriting legacy functions/methods.
Say we have a legacy function and a rewritten one:
var legacyFunction = function() { return 1; };
var reloadedFunction = function() { return 1; };
Is it possible to compare legacyFunction
and reloadedFunction
side-by-side, in the context where they are executed in production?
I have in mind something along those lines:
return rewriteLegacyCode((usagePerDevice, steps) => {
// broken implementation
for (let i = 0; i < inclusiveVolumeSteps.length; i++) {
if (usage >= steps[i].volume && usage < steps[i + 1].volume) {
return inclusiveVolumeSteps[i];
}
}
return undefined;
}).withNewVersion((usagePerDevice, steps) => {
return steps.findLast((step) => step.volume <= usagePerDevice});
})
.compareResults(usagePerDevice, inclusiveVolume)
.trustNewVersion();
I am looking for a nice implementation
I myself wrote the following code -- so far only dealing with non-async stuff: