The Tragic Death of Inheritance in Programming Languages

2023/07/03
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

In recent years, programming languages like Rust and Go have been challenging the traditional concept of inheritance. Many engineers are joining the movement, but what is the reason behind this shift? Is inheritance really on its way out?

Aviv Carmi, a seasoned developer, shares his personal journey in an article titled "The Tragic Death of Inheritance." Initially, Carmi was a strong advocate for inheritance, having worked with languages like Java, JavaScript, Python, C#, and PHP. However, after five years of extensive coding in Go, he had a change of heart.

Go, unlike other languages, does not support inheritance or abstract classes. At first, Carmi still argued for inheritance, but over time, he realized the power of composition. He now believes that composition is a superior choice in most cases.

So, what led to this shift in perspective? Carmi breaks it down in his article, highlighting the benefits of composition over inheritance. He emphasizes that changing one's mind is never easy, but it is essential for growth and improvement.

For developers keeping up with the latest industry trends, this article serves as a reminder that inheritance is not the only approach to object-oriented programming. By exploring alternatives like composition, developers can write more flexible and maintainable code.

Here's an example of how composition can be used in Go:

type Car struct {
    engine Engine
    wheels []Wheel
}

type Engine struct {
    // engine properties
}

type Wheel struct {
    // wheel properties
}

func (c *Car) Start() {
    c.engine.Start()
}

func (c *Car) Drive() {
    // driving logic
}

In this example, a Car struct is composed of an Engine and a slice of Wheel structs. The Car can start and drive by utilizing the methods of its composed components.

As the industry evolves, it is crucial for developers to embrace new paradigms and challenge established conventions. The death of inheritance may not be imminent, but it is essential to explore alternatives like composition to create more robust and scalable software.

Read Aviv Carmi's full article here to gain a deeper understanding of the shift away from inheritance and the rise of composition in modern programming languages.