To learn Clojure, one needs to learn the following things:
- Common libraries
- Structural editing
- REPL workflow
- Clojure idioms
- Minimize mutable states and side effects using derived values, immutable data structure, lambdas, and recursion.
- Put state mutation and side effects in one or a few places: concentration.
- Defer execution: describe and execute later.
The formula is data > functions > macros
- programs as data flows
- use “plain data”
- data defines control flow: code generation from data
- making DSL
Some data-driven examples:
Hiccup: reprsent HTML using vectors and maps.
noprompt/garden: render CSS.
metosin/reitit: define routes.
Transparency Through Data
Transparency is about understanding, which is about prediction. More constraints result better transparency. Use data and DSL to add constraints:
- avoid loops/recursion
- look for matching and destructuring
- look for static structure
- use namespace and keyword
- use different and specific data types
- use spec for complex grammars and validation