Post

One simple programming lesson I'd LOVE to help new programmers get right: Stop using inheritance for everything. I don't know what it is, but I feel like it has to be something about how educational content is structured by either: - The formal education system - and/or online learning platforms

... but anecdotally, I have continued to see inheritance get completely overused when developing software. I'm also speaking about this because *I* was a huge offender of this early in my career. I wrote absurd amounts of code that completely abused inheritance.

Why the heck do you think I have an entire course on refactoring?! My hunch, and I don't want to upset too many people (just a few), is the following: - People start learning to code - They eventually come across Dont Repeat Yourself (DRY)

- They start to see patterns in their code and start over-using DRY because if it looks remotely similar, we might as well refactor it to a common spot! - These developers start learning OOP principles

0 reposts2 likes

- Inheritance is the one that sticks because we always talk about memorable things like how a car is a vehicle and a cat and dog are animals - People suck at creating composition examples I guess, so nobody remembers to use it??? (The jury is still out on this)

Since DRY is the single most important thing evarrrr (please pick up on the sarcasm, I beg you) ANDDD we need a common spot to put that reusable code for easy access... We can put it into the base class!

Nice, now any time we want to use that helper method, we can just make sure our class inherits from the base class. Awesome! Oh, now we need to customize it a bit for this new class? No worries, we'll just override that behavior in this class. Perfect!