-
Transparency -> understanding -> prediction
-
Constraints narrow down possibilities.
- static types
- immutability
- pure function
-
以搜尋字串來舉例,看看下列的實作,哪一個比較容易預測?哪一個容易理解?
- clojure 的實作:不保証程式會停。
- re-find 的實作:保証一定會停。
- RE2/J 的實作:會停而且只使用 linear 的時間。
-
愈 powerful 的解法,就愈不 predicatable。
- With great power comes with great unpredicatability.
-
Rule of least power
- literal map Clojure literal map can be used to define function with a single argument and small domain.
- destructure
- compojure
- yada
- Datomic
- graphQL
- integrant
- Avoid loops and recursion (= avoid turing complete)
- Look for matching and destructuring
- Look for static structure
- Make use of :namespaced/keyword
- namespaced/keyword 可以繼承
- Make use of diffearent types
- 利用 type 來做 case statement
- Make use of spec for complex grammars
Clojure 有三種實作類似 function semantics 的方式:
- literal map
- defn
- macro
- 方法一,最 predictable 也最 limited 。
- 方法三,最 powerful 同時也最 unpredictable