# Libs vs Frameworks, Middle-Level Regularities vs Theories

![](https://substackcdn.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c13d462-eebe-4336-a7c1-66109662cdac_1073x1022.png)

Recently, a friend of mine brought out the essential distinction between [libraries and frameworks](https://www.brandons.me/blog/libraries-not-frameworks) in software engineering.

A library is a small software program that does one thing, does it cleanly, and lets you apply this thing to whatever you want. It lives and dies by [the UNIX philosophy](https://en.wikipedia.org/wiki/Unix_philosophy) and the [Keep It Simple Stupid (KISS) principle](https://en.wikipedia.org/wiki/KISS_principle). At its heart, a library is the digital equivalent of a hammer.

Whereas a framework comes with a whole approach to solving many problems at once, with a common unified and cleaned abstraction. These days the word gets used mostly for web frameworks like [React](https://react.dev/), but it applies whenever the program you use dictates how the full thing must be done (the technical term is [inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control)). So a framework is much more like a massive and complex factory that works amazingly well for a specific type of product, defined in a particular way.

At its core, this dichotomy is between low-level simplicity, which is infinitely composable and easier to use but also requires more repeated work to build larger wholes, and complex abstraction which captures some core patterns and intuitions but forces you to follow its rules and constraints.

This also means that a nice small library can easily live for as long as the programming language it uses exists and is in use, with next to no maintenance, whereas frameworks require armies of developers to update and anticipate the needs of their users, constantly refactoring the architecture and abstraction because any change reverberates everywhere, until users start dropping en masse for the next framework.

What’s unexpected is that this split also captures a core distinction in the practice of science, highlighted by the great Hasok Chang in his masterpiece “[Inventing Temperature](https://global.oup.com/academic/product/inventing-temperature-9780195337389)”: the distinction between middle-level regularities and high-level theories.

Following Herbert Feigl, Chang distinguishes the empirical laws that simply capture and compress some core phenomena ([Archimedes’ law of the lever](https://en.wikipedia.org/wiki/Lever#Law), [Snell-Descartes’ law of refraction](https://en.wikipedia.org/wiki/Snell%27s_law), [the ideal gas law](https://en.wikipedia.org/wiki/Ideal_gas_law)…), which he calls middle-level regularities, from the complex high-level theories that aim to unify and explain all phenomena in a domain ([Newtonian Mechanics](https://en.wikipedia.org/wiki/Classical_mechanics#Newtonian_mechanics), [Maxwell’s Electromagnetism](https://en.wikipedia.org/wiki/Maxwell%27s_equations), [Lavoisier’s Chemistry](https://en.wikipedia.org/wiki/Antoine_Lavoisier#Contributions_to_chemistry)…)

The latter clearly compresses and simplifies much more, giving you an incredible reach on the moment. But Feigl and Chang’s point is that theories tend to get invalidated and replaced by more complex and subtler ones, often built on completely different ([incommensurable](https://plato.stanford.edu/entries/incommensurability/)) abstractions; not so much middle-level regularities, which at worst get clearer bounds on their range of application.

As Chang puts it:

> Herbert Feigl emphasized that the stability of empirical science lies in the remarkable degree of robustness possessed by certain middle-level regularities, a robustness that neither sense-data nor high-level theories can claim: ‘‘I think that a relatively stable and approximately accurate basis—in the sense of testing ground—for the theories of the factual sciences is to be located not in individual observations, impressions, sense-data or the like, but rather in the empirical, experimental laws’’ (Feigl 1974, 8). For example, weight measurements using balances rely on Archimedes’s law of the lever, and observations made with basic optical instruments rely on Snell’s law of refraction. These laws, at least in the contexts of the measurements they enable, have not failed and have not been questioned for hundreds of years.

\- Hasok Chang, [Inventing Temperature](https://global.oup.com/academic/product/inventing-temperature-9780195337389?cc=gb&lang=en&), p52

So middle-level regularities act like libraries: always there for you, but never overreaching, leaving you most of the heavy lifting. Whereas theories are frameworks that empower you, but must survive more and more pressure from the experimental data and user needs, until they get at replaced (as emphasized by [among others](https://en.wikipedia.org/wiki/Gaston_Bachelard#Epistemological_breaks:_the_discontinuity_of_scientific_progress) [Kuhn](https://en.wikipedia.org/wiki/Thomas_Kuhn) and his paradigms).

Maybe one epistemological inspiration we can take from this analogy is to search for the libraries/regularities hidden in our theories, and attempt to carve them out. From these, we might build many theories that will rise and fall, leaving only dust, successors, and a handful of eternal libraries.