This is a note of the Rich Hickey’s Maybe Not Talk.
Motivation
Null is a billion dollar mistake. However, it is useful in the following places:
- optional parameters
- conditional provision in returns
- managing partial information in aggreated data
However, in static typed langauge, change a parameter to be optional (weak requirement) or return a non-optional result (strong promise) break existing callers. Haskell Maybe
is not a union type. Either
is not associative/commutattive/composable/symmetric. Kotlin and and Scala Dotty have union type. Clojure has spec/nilable
and spec/or
.
Partial Information
Aggreate is a flock/herd of information that travels together. Maps are mathematical functions, also true in Clojure.
Records/Fiedls/Product Types are place-oriented programming (PLOP): field names are not first-class indices (not functions). The product type complects meaning and place.
speck/keys
are independent, reusable attributes. They aggregate to form schema – infomration that travles together. The objectives of schema are wrong:
- maximize schema reuse, don’t want context-driven proliferation, yields more code, less reuse.
- support symmetric request/response: call partially filled in, get more filled in result.
- information-building pipelines: many partial information increments.
It is wrong when you specify req
or opt
because it has no usage context. There is nothing about optionality, when something is missing from a ste, leave it out. Schemas are nested deeply, so are optionality.
Solution
The solution is to split apart schema, the shape, from selection, what’s required/provided in a context.
In schema, only describe shapes only, no requirement. In usage context, for example in function call, define the requirement.
Things to fix spec
:
- schema/select replaces keys
- better programmatic manipulation of specs
- refine
fn
specs