Member-only story
Why Go, Rust, Nim, and Other Emerging Languages Abandon Inheritance and Constructors
In the evolution of modern programming languages, emerging languages like Go, Rust, and Nim have increasingly shifted towards composition over inheritance, and one of the key expressions of this shift is their abandonment of traditional constructors. This stands in stark contrast to many traditional object-oriented programming (OOP) languages like C++ or Java, which heavily rely on constructors. So, why have these emerging languages chosen to abandon the concept of constructors? In this article, we’ll explore this question from a specific perspective.
The Essence of Object-Oriented Programming: Code Archiving
The essence of object-oriented programming (OOP) is, in fact, a way to manage and organize large amounts of code and data. Each class can be viewed as a document box that groups similar things together. For example, cats and tigers both belong to the cat family, and in code, they may inherit from the same base class (e.g., Animal
).
In practice, we want to organize code in a way that makes it easier to find and reuse. For instance, during queries, we only need to access the parent class to find all of its subclasses, thus quickly locating the relevant content. With inheritance, we can create higher-level…