OOP is Not What You Think It Is

Post Stastics

  • This post has 1665 words.
  • Estimated read time is 7.93 minute(s).

Introduction

Object-Oriented Programming (OOP) has become one of the dominant paradigms in software development. When most developers discuss OOP, they are referring to the features of C++, Java, Python, or similar languages—often focusing on classes, inheritance, and polymorphism. But the term “Object-oriented programming” has a richer, deeper history that many modern implementations obscure or overlook. In this article, we will explore the original vision of OOP as conceived by Alan Kay and others at Xerox PARC, and how it was implemented in the Smalltalk language. We will then contrast this original vision with modern implementations of OOP in languages like C++ and Java, and finally, discuss why revisiting the Smalltalk philosophy could offer a better approach to software design, with a focus on message passing rather than on objects.

The Birth of Object-Oriented Programming

OOP’s origins lie in the early work of Alan Kay and his colleagues at Xerox PARC in the 1970s. Kay, who is often credited as the father of OOP, envisioned a new way to think about programming. His inspiration came from the idea of objects as independent, self-contained entities that interact with each other through messages. These objects were intended to model real-world entities and encapsulate both data and behavior. This view of computing was heavily influenced by Kay’s interest in human-computer interaction and his desire to make programming more intuitive.

In Kay’s vision, OOP was not about the syntax or structure of code as we know it today. Instead, it was about building systems where the behavior of software emerged from the interaction of objects. These objects would send and receive messages, much like how people communicate with each other. The message-passing concept in OOP was meant to create highly flexible and modular software systems that were easily understood and adaptable.

This vision was brought to life in the Smalltalk programming language, which was created by Kay and his colleagues, including Dan Ingalls, Adele Goldberg, and others at Xerox PARC in the 1970s and 1980s. Smalltalk was built from the ground up with the idea that everything in the system, including user interfaces, was an object. However, Smalltalk was much more than just a programming language; it represented a new way of thinking about software design.

Smalltalk: The Pure Vision of OOP

Smalltalk is often regarded as the first “pure” object-oriented programming language. Its design was revolutionary in that it completely embraced OOP principles. In Smalltalk, everything is an object, including primitive types like numbers and characters. More importantly, all interactions between objects occur through message passing, which means that instead of calling functions or methods on an object (as in traditional procedural programming), one object sends a message to another and waits for a response.

Key Principles of Smalltalk OOP

  1. Everything is an Object
  2. In Smalltalk, objects are the fundamental building blocks of the system. Unlike in languages like C or C++, where variables and functions are separate, in Smalltalk, everything is an object that encapsulates both state (data) and behavior (methods).
  3. Message Passing
  4. The core interaction in Smalltalk is message passing. An object doesn’t call methods or functions on another object. Instead, it sends a message to the other object, requesting some action. The object receiving the message then responds accordingly. This is akin to how people communicate—one might ask a question and get an answer in return.
  5. Encapsulation
  6. Objects in Smalltalk encapsulate their data and behavior, hiding their internal state from the outside world. This ensures that an object’s internal workings cannot be directly modified, which promotes modularity and reduces the complexity of systems.
  7. Inheritance and Polymorphism
  8. While inheritance and polymorphism are important in Smalltalk, they are secondary to message passing. Inheritance allows objects to inherit behaviors from their parent classes, and polymorphism allows objects of different types to respond to the same message in different ways.
  9. Dynamic Typing
  10. Smalltalk is a dynamically typed language, meaning that the type of an object is determined at runtime. This allows for greater flexibility in how objects can interact, as long as they respond to the correct messages.
  11. Simplicity and Uniformity
  12. One of the most profound aspects of Smalltalk was its simplicity. In Smalltalk, everything is treated uniformly—objects, methods, classes, and even the environment itself are all represented as objects. This reduces the complexity of the system and makes it easier to understand and extend.

The Shift: C++ and Modern OOP

In contrast to Smalltalk’s pure object-oriented approach, modern OOP languages like C++ and Java took a somewhat different direction. While they retained the core concepts of inheritance, encapsulation, and polymorphism, they deviated from the original message-passing paradigm and instead focused on classes, objects, and methods.

C++: The Rise of the Class-Based Model

C++ was developed by Bjarne Stroustrup in the early 1980s as an extension of the C programming language. It introduced object-oriented features like classes, inheritance, and polymorphism, but with a significant twist: C++ remained fundamentally a procedural language at its core, with object-oriented features added on top. This made C++ a hybrid language—one that allowed developers to program using both object-oriented and procedural techniques.

While C++ introduced important concepts such as classes (which define the structure and behavior of objects) and encapsulation (hiding data within objects), it did not prioritize message passing as the primary way for objects to interact. Instead, C++ objects communicate by invoking methods (or functions) on each other, which is a more traditional way of structuring software.

C++ also introduced concepts like multiple inheritance, which allowed a class to inherit from more than one base class, and operator overloading, which allowed developers to define custom behaviors for operators like + or ==. These features added flexibility but also increased the complexity of the language.

Modern OOP Languages

In modern OOP languages like Java, Python, and C#, the focus remains on classes, inheritance, and methods. These languages have largely abandoned the message-passing paradigm in favor of more structured models of communication, where objects explicitly call methods on each other. For example, in Java, objects often interact by invoking methods directly on one another, rather than sending messages.

While modern OOP languages have added powerful features like interfaces, abstract classes, and lambda expressions, they have also become more rigid and structured, emphasizing class hierarchies and inheritance. The result is a shift from the fluid, dynamic vision of OOP in Smalltalk to a more formal and often cumbersome model of software design.

The Case for Returning to Smalltalk’s Vision

Despite the success of C++, Java, and other modern OOP languages, there is a growing sense that something essential has been lost. Many developers feel that modern OOP has become too focused on objects rather than on message passing, which was the core idea of OOP in Smalltalk.

Why Message Passing Matters

The original idea behind message passing was that it allowed objects to be more flexible and independent. In Smalltalk, objects do not need to know the details of each other’s implementation—they simply need to know how to respond to a message. This allows for greater decoupling between objects, which in turn makes the system more modular and maintainable.

In contrast, modern OOP languages like C++ and Java often rely heavily on method calls and class hierarchies, which can create tight coupling between objects. For example, in Java, a subclass must inherit from a superclass to reuse behavior, which leads to a rigid class hierarchy. This is less flexible than the message-passing approach in Smalltalk, where objects can communicate without needing to share a common inheritance tree.

Furthermore, modern OOP often requires developers to define large numbers of methods and interfaces to express behavior, leading to boilerplate code and complex inheritance structures. Smalltalk’s message-passing model allows for a much more minimalist approach, where the behavior of a system emerges from the interactions between objects rather than from predefined class structures.

The Simplicity of Smalltalk

Another compelling reason to revisit Smalltalk’s vision of OOP is its simplicity. Smalltalk’s uniformity—where everything is an object and all interactions are message-based—makes the system easier to understand and extend. This simplicity contrasts sharply with the complexity of modern OOP systems, which often require developers to understand complex inheritance hierarchies, interfaces, and design patterns.

The Smalltalk approach encourages developers to focus on what an object can do (its messages) rather than on how it does it (its internal methods). This leads to more flexible, modular software systems that are easier to test, extend, and maintain.

Emphasizing Behavior Over Structure

Lastly, returning to Smalltalk’s message-passing paradigm would encourage a greater focus on behavior rather than on structure. In modern OOP, much of the emphasis is on defining clear class structures and managing relationships between classes. While this approach is effective in some situations, it often leads to a focus on architecture at the expense of behavior.

Message passing, on the other hand, encourages a more dynamic, behavior-driven approach to software design. In a message-passing system, developers focus on how objects interact with one another, rather than on how they are organized in a class hierarchy. This can lead to more expressive and elegant designs.

Conclusion

Object-oriented programming, as originally envisioned by Alan Kay and implemented in Smalltalk, is fundamentally different from the modern OOP paradigm that is prevalent

in languages like C++ and Java. The original Smalltalk approach emphasized message passing, dynamic behavior, and simplicity. In contrast, modern OOP often focuses on rigid class structures, inheritance, and method calls.

While modern OOP has certainly contributed to the development of powerful and scalable software systems, it has also led to increased complexity and a loss of the flexibility and modularity that made Smalltalk’s vision so powerful. By returning to the message-passing philosophy of Smalltalk, we could create more flexible, modular, and maintainable software systems that are easier to understand and extend. OOP, in its original form, was never about objects—it was about communication between objects, and it’s time we returned to that fundamental insight.

Leave a Reply

Your email address will not be published. Required fields are marked *