← @bgSponge

Constraints Liberate, Liberties Constrain — Runar Bjarnason

Summary

Runar Bjarnason argues in a Scala World talk that limiting a component's expressive power makes systems built from it easier to compose and reason about.

  1. Premature loss of precision creates technical debt.

    Bjarnason compares it to detonating dynamite early: once a program has emitted printer control codes, built a SQL string, or rounded the square root of eight to a double, the structure needed for later composition is gone.

  2. Abstraction makes precision possible.

    A non-generic signature he shows has something like four billion to the four-billionth power implementations, while a function from any type A to the same type A has one sensible implementation: return its input.

    the purpose of abstraction is not to be vague but to create a new semantic level in which one can be absolutely precise

    if you constrain yourself to a small language you can always embed that language in a larger one later on

  3. Applicative functors compose mechanically and monads do not.

    A monad adds join and flatMap to an applicative functor, a mappable type whose values can be combined side by side, but composing two monads needs code specific to them, such as monad transformers.

  4. Futures obey algebraic laws that Akka actors lack.

    An actor's receive function takes Any and returns Unit, can change behavior between calls, and so supports no algebraic reasoning, while futures follow the monad laws.

  5. A constraint on a producer frees its consumers.

    In the currying adjunction between pairs and functions, a less capable producer fits strictly more consumers, and Bjarnason says most software we write consumes other software.

    our programs can do strictly more things if we have side effects but we can conclude strictly fewer things about them

    a constraint at one level leads to freedom and power at another level

Read the original ↗Save to Sponge

Summarized with Sponge. Quotes are the author’s own words.

More from @bg

All readings →