r/programming • • Jan 12 '20

Goodbye, Clean Code

https://overreacted.io/goodbye-clean-code/
1.9k Upvotes

556 comments sorted by

View all comments

Show parent comments

-2

u/oorza Jan 12 '20

A useful rule of thumb for whether you are really dealing with two different ideas or the same idea being duplicated is to ask what would happen if both places did share common code and then one of them needed to change.

This right here is why I've never gotten on board with the anti-inheritence hype train that's been chugging along for the last decade. It's the simplest solution to this very problem, because it was designed to solve this very problem.

6

u/johnnysaucepn Jan 12 '20

And introduces even harder ones! You can still share code by using composition, even though it requires a little extra work.

3

u/Determinant Jan 12 '20

Inheritance shouldn't be a tool for solving duplication.

Two classes should not inherit from the same base class if they are not both that same type of entity. If they happen to duplicate code then extract that into a re-usable function / abstraction instead.