News for hackers. Stuff that matters.
Re:Don't DRY Your Code Prematurely by Spivak on Friday May 31, 2024 @12:08AM (#40531395)
Single use? No way that's what multiple inheritance and mixins are for. Inheritance being only for code reuse is explicitly about not creating a taxonomy. No more is-a just, "I need this code here." Hey this thing behaves like a mapping inherit from the MutipleMapping and get all the usual mapping methods for free. Hey this model needs created/updated_at, inherit from ChangeTracking and get those fields and helper methods for free.

Has-a doesn't make sense for code like the literal text reuse. It makes sense for composition and encapsulation.

Edit: I'm now realizing that Python has one of the only sane multiple inheritance implementations. It's no wonder the rest of y'all hate it.

There are no comments on this comment yet.