What is a leaky abstraction?

Created time
Mar 18, 2023 12:54 PM
Main Box
Software Engineering

What is a leaky abstraction?

notion image
Before diving into the concept of a leaky abstraction, let's first clarify the term "abstraction" in the context of computer programming. Abstraction is a fundamental principle of software engineering that simplifies complex systems by reducing the level of detail and complexity of a system. Essentially, it allows programmers to hide the details of a given aspect of a system behind a simpler interface, enabling them to create cleaner, more maintainable code.
Now, let's explore the concept of a leaky abstraction.

Intuitive Understanding of Leaky Abstraction

A leaky abstraction is an abstraction that, while attempting to simplify a system or coding process, unintentionally exposes the underlying complexity or details it was meant to hide. This "leak" may occur due to limitations, assumptions, or even design flaws within the abstraction. Consequently, developers using the abstraction need to be aware of its underlying intricacies, thus diminishing the benefits of abstraction.
Consider the analogy of a water container with a small hole. Ideally, the container should hold the water without any leakage. However, the small hole causes it to "leak," revealing the underlying problem. Similarly, a leaky abstraction is intended to conceal certain details but fails to do so completely.

Formalized Definition of Leaky Abstraction

A formalized definition of leaky abstraction can be described as a situation where an incomplete or flawed abstraction leads to the exposure of the underlying system or implementation details to the users interacting with the abstraction. Consequently, the users are forced to deal with the abstraction's underlying complexities, which should have been hidden, thus reducing the abstraction's effectiveness.


Spolsky's article cites many examples of leaky abstractions.
This leads Spolsky to formulate his Law of Leaky Abstractions:
  • All non-trivial abstractions, to some degree, are leaky.