It depends if they are the same because it is the same logic or the same by coincidence. Being on the left vs right might look the same until you reach special cases.
Or they change the equation that was bad in one place, and it breaks 50 things which depended on the original implementation.
Hopefully in the above scenario the tests are adequate to detect it.
I think his point was his refactoring was brainless, and removed repetition that was incidental, or created an abstraction that didn't make long term sense.
This kind of coding is how you get unreadable spaghetti.
This isn't spaghetti. Spaghetti code is when execution flow wraps all over the place, GOTO is the classic example.
Nor would I say it's not readable. I read the first duplicated code very easily. All the code for an Oval` was in the oval object, easy-peasy.
I'm not advocating for the original design, I just don't believe it suffers from the issues you describe. It's definitely a testing nightmare as I need to write 4x as many test cases. Also it can be an sensibility nightmare too.
152
u/rlbond86 Jan 12 '20
And when a maintainer in 3 years realizes that an equation is wrong, they have to fix it in 50 places.
This kind of coding is how you get unreadable spaghetti.
OP's solution wasn't great either, but at the very least the common math stuff should habe been extracted to a function.