Hacker News new | past | comments | ask | show | jobs | submit login

The concern I have with this approach is how easy it is forget to alter one of the variants when you alter one of them.

How do you know the code you're touching has other versions that are semantically the same and should also be altered?[1]

How do you avoid having to fix the same bug several times because you bug-fixed one place but not the others?

How do you avoid the technical debt that builds over time when instances of the pattern within the codebase are each at subtly different "versions" with similar, but not identical, semantics (even though identical would have worked fine?)

[1] Of course, DRY code has the inverse: How do you know if an existing function to do what you want to do already exists so you can avoid duplicating the extraction?

Where my opinion falls today is: A slightly more complex solution is often less risky and more maintainable than the straightforward duplication solution because at least the complex one looks complex to a would-be maintainer who will at least be aware of things up front, whereas duplicated code can have a bunch of hidden costs whenever it's touched that won't necessarily become apparent until later when the presence of that technical debt throws a monkey wrench into unrelated plans.




If your variants need to be similar, that alone is a great reason to abstract. It makes the abstraction more valuable.

Meanwhile, there could easily be transformative code that just computes some stuff you often need. In those cases altering one variant need not effect the others.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: