The Forgotten History of OOP

Eric Elliott

The Forgotten History of OOP

Smoke Art Cubes to Smoke — MattysFlicks — (CC BY 2.0)

Note: This is part of the “Composing Software” series on learning functional programming and compositional software techniques in JavaScript ES6+ from the ground up. Stay tuned. There’s a lot more of this to come!
< Previous | << Start over at Part 1

Most of the programming paradigms we use today were first explored mathematically in the 1930s with lambda calculus and the Turing machine, which are alternative formulations of universal computation (formalized systems which can perform general computation). The Church Turing Thesis showed that lambda calculus and Turing machines are functionally equivalent — that anything that can be computed using a Turing machine can be computed using lambda calculus, and vice versa.

Note: There is a common misconception that Turing machines can compute anything computable. There are classes of problems (e.g., the halting problem) that can be computable for some cases, but are not generally computable for all cases using Turing machines. When I use the word “computable” in this text, I mean “computable by a Turing machine”.

Lambda calculus represents a top-down, function application approach to computation, while the ticker tape/register machine formulation of the Turing machine represents a bottom-up, imperative (step-by-step) approach to computation.

Low level languages like machine code and assembly appeared in the 1940s, and by the end of the 1950s, the first popular programming high-level languages implementing both functional and imperative approaches appeared. Lisp dialects are still in common use today, including Clojure, Scheme, AutoLISP, etc. FORTRAN and COBOL both appeared in the 1950s and are examples of imperative high-level languages still in use today, though C-family languages have replaced both COBOL and FORTRAN for most applications.

Both imperative programming and functional programming have their roots in the formal mathematics of computation, and predate digital computers. Object Oriented Programming (OOP) came later, and has its roots in the structured programming revolution that arrived in the 1960s and 1970s.

The first objects I know of were used by Ivan Sutherland in his seminal Sketchpad application, created between 1961 and 1962 and published in his Sketchpad Thesis in 1963. The objects represented graphical glyphs displayed on an oscilloscope screen (possibly the first use of a graphical computer monitor), and featured inheritance via dynamic delegates, which Ivan Sutherland called “masters” in his thesis. Any object could become a “master”, and additional instances of the objects were called “occurrences”. This makes Sketchpad the first known programming language that implemented prototypal inheritance.

The first programming language widely recognized as “object oriented” was Simula, specified in 1965. Like Sketchpad, Simula featured objects, but also featured classes, class inheritance, subclasses, and virtual methods.

Note: A virtual method is a method defined on a class which is designed to be overridden by subclasses. Virtual methods allow a program to call methods that may not exist at the moment the code is compiled by employing dynamic dispatch to determine what concrete method to invoke at runtime. JavaScript features dynamic types and uses the delegation chain to determine which methods to invoke, so does not need to expose the concept of virtual methods to programmers. Put another way, all methods in JavaScript use runtime method dispatch, so methods in JavaScript don’t need to be declared “virtual” to support the feature.

What the Father of Object-Oriented Programming Wants You to Know About OOP

“I made up the term ‘object-oriented’, and I can tell you I didn’t have C++ in mind.” ~ Alan Kay, OOPSLA ‘97

Alan Kay coined the term “Object Oriented Programming” in reference to the Smalltalk programming language (1972), which was developed by Alan Kay, Dan Ingalls, and others at Xerox Park for a laptop project called “Dynabook”. Smalltalk was more object-oriented than Simula — everything in Smalltalk is an object, including classes, integers, and blocks (closures). The original Smalltalk-72 did not feature subclassing. That was introduced in Smalltalk-76.

While Smalltalk supported classes and eventually subclassing, Smalltalk was not about classes or subclassing things. It was a functional language inspired as much by Lisp as it was by Simula. Alan Kay considers classes as a code reuse mechanism to be a mistake, and the industry’s focus on subclassing to be a distraction from the true benefits of object oriented programming.

Because they share so many features in common, I like to say that JavaScript is Smalltalk’s revenge on the world’s misunderstanding of OOP. Both Smalltalk and JavaScript support:

  • Objects
  • First-class functions and closures
  • Dynamic types
  • Late binding (functions/methods changeable at runtime)
  • OOP without class inheritance

“I’m sorry that I long ago coined the term “objects” for this topic because it gets many people to focus on the lesser idea. The big idea is messaging.”
~ Alan Kay

In a 2003 email exchange, Alan Kay clarified what he meant when he called Smalltalk “object-oriented”:

“OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things.”
~ Alan Kay

In other words, according to Alan Kay, the essential ingredients of OOP are:

  • Message passing
  • Encapsulation
  • Dynamic binding

Notably, inheritance and polymorphism were NOT considered essential ingredients of OOP by Alan Kay, the man who coined the term and brought OOP to the masses.

The Essence of OOP

The combination of message passing and encapsulation serve some important purposes:

  • Avoiding shared mutable state by encapsulating state and isolating other objects from local state changes. The only way to affect another object’s state is to ask (not command) that object to change it by sending a message. State changes are controlled at a local, cellular level rather than exposed to shared access.
  • Decoupling objects from each other — the message sender is only loosely coupled to the message receiver, through the messaging API.
  • Adaptability and resilience to changes at runtime via late binding. Runtime adaptability provides many great benefits that Alan Kay considered essential to OOP.

These ideas were inspired by biological cells and/or individual computers on a network via Alan Kay’s background in biology and influence from the design of ARPANet (an early version of the internet). Even that early on, Alan Kay imagined software running on a giant, distributed computer (the internet), where individual computers acted like biological cells, operating independently on their own isolated state, and communicating via message passing.

“I realized that the cell/whole-computer metaphor would get rid of data[…]”
~ Alan Kay

By “get rid of data”, Alan Kay was surely aware of shared mutable state problems and tight coupling caused by shared data — common themes today.

But in the late 1960s, ARPAnet programmers were frustrated by the need to choose a data model representation for their programs in advance of building software. Developers wanted to get away from that because locking yourself into a data representation early could make it hard to change things later.

The problem was that different data representations required different code and different syntax to access in the programming languages of the day. The holy grail would be a universal way to access and manipulate data. If all data looked the same to the program, it would solve a lot of software evolution and maintenance problems for software developers.

Alan Kay was trying to “get rid of” the idea that data and software were somehow separate things — they’re not treated differently in Lisp or Smalltalk. There is no separation between what you can do with data (values, variables, data structures, etc…) and software constructs like functions. Functions are first-class citizens, and software is allowed to change at runtime. In other words, in Smalltalk, data does not get special, privileged treatment.

Alan Kay also saw objects as algebraic structures, which make certain mathematically provable guarantees about their behaviors:

“My math background made me realize that each object could have several algebras associated with it, and there could be families of these, and that these would be very very useful.”
~ Alan Kay

This has proven to be true, and forms the basis for objects such as promises and lenses, both inspired by category theory.

The algebraic nature of Alan Kay’s vision for objects would allow objects to afford formal verifications, deterministic behavior, and improved testability, because algebras are essentially operations which obey a few rules in the form of equations.

In programmer lingo, algebras are abstractions made up of functions (operations) accompanied by specific laws enforced by unit tests those functions must pass (axioms/equations).

Those ideas were forgotten for decades in most C-family OO languages, including C++, Java, C#, etc., but they’re beginning to find their way back into recent versions of most widely used OO languages.

You might say the programming world is rediscovering the benefits of functional programming and reasoned thought in the context of OO languages.

Like JavaScript and Smalltalk before it, most modern OO languages are becoming more and more “multi-paradigm languages”. There is no reason to choose between functional programming and OOP. When we look at the historical essence of each, they are not only compatible, but complementary ideas.

What is essential to OOP (according to Alan Kay)?

  • Encapsulation
  • Message passing
  • Dynamic binding (the ability for the program to evolve/adapt at runtime)

What is non-essential?

  • Classes
  • Class inheritance
  • Special treatment for objects/functions/data
  • The new keyword
  • Polymorphism
  • Static types
  • Recognizing a class as a “type”

If your background is Java or C#, you may be thinking static types and Polymorphism are essential ingredients, but Alan Kay preferred dealing with generic behaviors in algebraic form. For example, from Haskell:

fmap :: (a -> b) -> f a -> f b

This is the functor map signature, which acts generically over unspecified types a and b, applying a function from a to b in the context of a functor of a to produce a functor of b. Functor is math jargon that essentially means “supporting the map operation”. If you’re familiar with [].map() in JavaScript, you already know what that means.

Here are two examples in JavaScript:

// isEven = Number => Boolean
const isEven = n => n % 2 === 0;
const nums = [1, 2, 3, 4, 5, 6];
// map takes a function `a => b` and an array of `a`s (via `this`)
// and returns an array of `b`s.
// in this case, `a` is `Number` and `b` is `Boolean`
const results = nums.map(isEven);
console.log(results);
// [false, true, false, true, false, true]

The .map() method is generic in the sense that a and b can be any type, and .map() handles it just fine because arrays are data structures that implement the algebraic functor laws. The types don’t matter to .map() because it doesn’t try to manipulate them directly, instead applying a function that expects and returns the correct types for the application.

// matches = a => Boolean
// here, `a` can be any comparable type
const matches = control => input => input === control;
const strings = ['foo', 'bar', 'baz'];
const results = strings.map(matches('bar'));
console.log(results);
// [false, true, false]

This generic type relationship is difficult to express correctly and thoroughly in a language like TypeScript, but was pretty easy to express in Haskell’s Hindley Milner types with support for higher kinded types (types of types).

Most type systems have been too restrictive to allow for free expression of dynamic and functional ideas, such as function composition, free object composition, runtime object extension, combinators, lenses, etc. In other words, static types frequently make it harder to write composable software.

If your type system is too restrictive (e.g., TypeScript, Java), you’re forced to write more convoluted code to accomplish the same goals. That doesn’t mean static types are a bad idea, or that all static type implementations are equally restrictive. I have encountered far fewer problems with Haskell’s type system.

If you’re a fan of static types and you don’t mind the restrictions, more power to you, but if you find some of the advice in this text difficult because it’s hard to type composed functions and composite algebraic structures, blame the type system, not the ideas. People love the comfort of their SUVs, but nobody complains that they don’t let you fly. For that, you need a vehicle with more degrees of freedom.

If restrictions make your code simpler, great! But if restrictions force you to write more complicated code, perhaps the restrictions are wrong.

What is an Object?

Objects have clearly taken on a lot of connotations over the years. What we call “objects” in JavaScript are simply composite data types, with none of the implications from either class-based programming or Alan Kay’s message-passing.

In JavaScript, those objects can and frequently do support encapsulation, message passing, behavior sharing via methods, even subclass polymorphism (albeit using a delegation chain rather than type-based dispatch).

Alan Kay wanted to be rid of the distinction between the program and its data. JavaScript does that to some degree by putting methods on the same footing as data properties. You can assign any function to any property. You can build object behaviors dynamically, and change the meaning of an object at runtime.

An object is simply a composite data structure, and does not require anything more to be considered an object. But programming using objects does not make your code “object-oriented” any more than programming with functions makes your code “functional”.

OOP is not Real OOP Anymore

Because “object” in modern programming languages means much less than it did to Alan Kay, I’m using “component” instead of “object” to describe the rules of real OOP. Many objects are owned and manipulated directly by other code in JavaScript, but components should encapsulate and control their own state.

Real OOP means:

  • Programming with components (Alan Kay’s “object”)
  • Component state must be encapsulated
  • Using message passing for inter-object communication
  • Components can be added/changed/replaced at runtime

Most component behaviors can be specified generically using algebraic data structures. Inheritance is not needed here. Components can reuse behaviors from shared functions and modular imports without sharing their data.

Manipulating objects or using class inheritance in JavaScript does not mean that you’re “doing OOP”. Using components in this way does. But popular usage is how words get defined, so perhaps we should abandon OOP and call this “Message Oriented Programming (MOP)” instead of “Object Oriented Programming (OOP)”?

Is it coincidence that mops are used to clean up messes?

What Good MOP Looks Like

In most modern software, there is some UI responsible for managing user interactions, some code managing application state (user data), and code managing system or network I/O.

Each of those systems may require long-lived processes, such as event listeners, state to keep track of things like the network connection, ui element status, and the application state itself.

Good MOP means that instead of all of these systems reaching out and directly manipulating each other’s state, the system communicates with other components via message dispatch. When the user clicks on a save button, a "SAVE" message might get dispatched, which an application state component might interpret and relay to a state update handler (such as a pure reducer function). Perhaps after the state has been updated, the state component might dispatch a "STATE_UPDATED" message to a UI component, which in turn will interpret the state, reconcile what parts of the UI need to be updated, and relay the updated state to the subcomponents that handle those parts of the UI.

Meanwhile, the network connection component might be monitoring the user’s connection to another machine on the network, listening for messages, and dispatching updated state representations to save data on a remote machine. It’s internally keeping track of a network heartbeat timer, whether the connection is currently online or offline, and so on.

These systems don’t need to know about the details of the other parts of the system. Only about their individual, modular concerns. The system components are decomposable and recomposable. They implement standardized interfaces so that they are able to interoperate. As long as the interface is satisfied, you could substitute replacements which may do the same thing in different ways, or completely different things with the same messages. You may even do so at runtime, and everything would keep working properly.

Components of the same software system may not even need to be located on the same machine. The system could be decentralized. The network storage might shard the data across a decentralized storage system like IPFS, so that the user is not reliant on the health of any particular machine to ensure their data is safely backed up, and safe from hackers who might want to steal it.

OOP was partially inspired by ARPAnet, and one of the goals of ARPAnet was to build a decentralized network that could be resilient to attacks like atomic bombs.

A good MOP system might share those properties using components that are hot-swappable while the application is running. It could continue to work if the user is on a cell phone and they go offline because they entered a tunnel. It could continue to function if a hurricane knocks out the power to one of the data centers where servers are located.

It’s time for the software world to let go of the failed class inheritance experiment, and embrace the math and science principles that originally defined the spirit of OOP.

It’s time for us to start building more flexible, more resilient, better-composed software, with MOP and functional programming working in harmony.

Note: The MOP acronym is already used to describe “monitoring-oriented programming” and its unlikely OOP is going to go away quietly.

Don’t be upset if MOP doesn’t catch on as programming lingo.
Do MOP up your OOPs.

Learn More at EricElliottJS.com

Video lessons on functional programming are available for members of EricElliottJS.com. If you’re not a member, sign up today.


Eric Elliott is the author of “Programming JavaScript Applications” (O’Reilly), and cofounder of the software mentorship platform, DevAnywhere.io. He has contributed to software experiences for Adobe Systems, Zumba Fitness, The Wall Street Journal, ESPN, BBC, and top recording artists including Usher, Frank Ocean, Metallica, and many more.

He works remote from anywhere with the most beautiful woman in the world.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.