What is a pattern?

A properly captured by the Mind (of an external observer) into a named abstraction “frequently emerging arrangement”.

There are obvious weather patterns, seasonal patterns, social patterns, and so on.

The most “concrete” emergent patterns are the “structural patterns” – rivers, trees, proteins, biological species.

The most fundamental structural patterns has been captured as abstractions:

  • linear sequences
  • trees (acyclic directed graphs)
  • tables (lookup tables)

More abstractions has been derived

  • pairs (and n-tuples)
  • lists (of an arbitrary length)
  • sets (without any particular ordering)
  • matrices

Sets are special, because it is a pure abstraction of the Mind, like a Number or a Function (which represents a relation).

These abstractions are used in the “pattern-matching” DSLs of the classic ML-family languages (Ocaml, Haskell and Erlang).

Nesting

The most universal patten is, of course, nesting. Structural “blocks” within enzymes, enzymes within cells, organelles within cells, membranes of cells, tissues, organs, subsystems, organisms.

There is no surprise (at least to me) that a function composition is defined as nesting and that there is no other way.

Notice also that the most common interface-level pattern is “wrapping”, which is, of course, nesting.

Structural pattern-matching

This is what enzymes and other molecular biology machinery do, literally.

A particular molecular structures bind to particular sites (receptors) or fill particular kind of “slots” within a folded protein (which is what an enzyme is built off), changing its electro-chemical and thus “structural” properties, so it performs its “action”.

It seems to me that, our imperative “procedures” and even our pure mathematical functions are generalization of these universal patterns.

“Design” patterns

These are structural patterns too, but the structure is of the code (which is usually captures in “flow charts”) and of the data types, which all have their distinct “shapes” (the Algebraic data types).

So, a “design pattern” simply captures and names a common (frequently emergent) structural arrangements in the code.

It is a “higher-order abstraction”, so to speak.

Layers of DSLs

The most fundamental design pattern is “layers of DSLs”, which captures the universal notion of a layered hierarchical structure with clearly separated (by physical abstraction barriers) layers, so much so, that they, literally, “have no awareness” of existence of the layers above them or of more than one level below them.

This is how most of complex but stable (robust) biological systems have been built by Evolution (a trial-and-error process, which “selects” stable intermediate forms).

An interpreter

This is another universal pattern, which captures the subtle notion of using physical molecular arrangements as “instructions” (the data).

The DNA transcription machinery is an instance. There are several actual “interpreters” of DNA and RNA sequences within any cell.

So, having an interpreted DSL within a library (or a module) is a high-level universal pattern. The old-school MIT programmer’s knew this.