News for hackers. Stuff that matters.
Re:Goodbye, Clean Code by boffinism on Saturday January 11, 2020 @04:53PM (#22022599)
I think this highlights an important nuance to the Don't Repeat Yourself maxim. It's not just about whether two bits of code are similar now. It's about whether, when they change in future, they are likely to change in the same ways. If not, then DRYing up the code now is only making more work for yourself down the line.
Re:Goodbye, Clean Code by tudorpavel on Saturday January 11, 2020 @05:08PM (#22022689)
DRY is good but like any abstraction it has tradeoffs. It might give you a warm feeling to do the refactor, but you might end up with code that's harder to understand and harder to replace.
Re:Goodbye, Clean Code by erik_seaberg on Saturday January 11, 2020 @04:57PM (#22022629)
I've always found the https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle, where you derive from classes instead of editing them in-place, sort of appealing for this reason.
Re:Goodbye, Clean Code by terandle on Saturday January 11, 2020 @05:20PM (#22022769)
What is this implying? That instead of adding a property/method to a class you should instead create a child class that inherits from the original with the new properties? Sounds like a great way to have a very complicated class hierarchy IMO
Re:Goodbye, Clean Code by erik_seaberg on Saturday January 11, 2020 @05:24PM (#22022791)
Exactly that. Just because you want new behavior doesn't mean all the other consumers of that class also want it. The old behavior should still exist, and have a name. I'm not sure whether the idea was ever fully developed into patterns for replacing deep hierarchies with simplified classes that factor out some inheritance from otherwise-unused base classes.
Re:Goodbye, Clean Code by kbutler on Sunday January 12, 2020 @08:27PM (#22031118)
Prefer extension via composition for more flexibility than via inheritance, which tends to create overly rigid hierarchies.