4 ms·
> The best approach I've seen so far is to focus on "get rid of duplicate systems" In my experience this still requires finding the right balance, like almost
by cactus2093 7y ago
> The best approach I've seen so far is to focus on "get rid of duplicate systems"
In my experience this still requires finding the right balance, like almost anything else in programming. If you're too eager to get rid of duplication you can end up combining things that aren't actually quite the same and creating leaky abstractions that are a lot more painful than the almost-duplication was.
There's also sometimes a trade-off involved. Maintaining two very similar systems can be more work/require more engineers, but maintaining one system that is used in different ways can make you more likely to introduce bugs unexpectedly if you make a change focused on one particular use without testing all the others enough. It might depend on the particular system which cost is more acceptable.
- simonw 7y agoYeah I've definitely seen people refactor code to eliminate duplication in a way that turns out to be counter-productive a few weeks later, when it turns out the two places that use the code are evolving in different directions. I'm thinking more about duplicate systems. A really common pattern in a codebase that has been around for a few years is incomplete replacements: someone builds v2 of the checkout flow, but it never quite completely reaches feature parity with v1 for all of the edge cases so both of them stuck around. Kill those!
- Aeolun 7y agoIf you refactor to avoid duplication, refactor into an interface.
- makapuf 7y agoYes it's important to keep separate things that could be seen as duplicate but the meaning of which is different and will evolve differently. By example paying user and delivery user or provisioning an IP address and a physical server.
- gitgud 7y agoTrue, if you're a really good engineer, you might implement an add() function to remove the duplicated addition everywhere...
- Aeolun 7y agoOh. That’s helpful! Makes it much easier if you ever have to modify the behavior of addition! Like, if a new discovery in math is made and it turns out that 1+1 isn’t always 2.
- Viliam1234 7y agoThe real benefits will appear at testing, where you can replace the actual addition with a mock object that expects parameters 1 and 1 and returns a fixed value 2, without having to do the calculation.