Abstraction

23/09/2024

An abstraction takes something complicated and allows you to treat it as if it were something simple. It does the work of condensing the set of operations permitted by a primitive. In that sense, an abstraction can be thought of like a function that maps inputs (high-level operations) to outputs (primitive operations).

In the case of an abstraction, the high-level side should be smaller than the primitive side. A common anti-pattern with abstractions, which I've seen called the "inner-platform effect", is for the abstraction to mission-creep towards a 1:1 mapping of the underlying primitive.

Some abstractions enclose their primitives, whilst others partially or fully expose their primitives for use-cases that require greater sophistication. ActiveRecord attempts to enclose SQL, but actually fully exposes it for when its abstractions are not sufficient. React shields the developer from the statefulness of the DOM, but still provides "escape hatches".

An abstraction is an invitation to play one game, that of the abstraction, rather than an another, that of the primitive. The naive developer loses himself in the labyrinthe of an unsound abstraction's game.

A good test of the soundness of an abstraction is whether the developer is forced to understand the primitive in order to successfully operate the abstraction.