Skip to content

Instantly share code, notes, and snippets.

@humorless
Last active November 27, 2020 06:52
Show Gist options
  • Save humorless/c032fec5c4d7fec37d64a8310aa0d5ca to your computer and use it in GitHub Desktop.
Save humorless/c032fec5c4d7fec37d64a8310aa0d5ca to your computer and use it in GitHub Desktop.
Transparency through Data --- James Reeves
  1. Transparency -> understanding -> prediction

  2. Constraints narrow down possibilities.

    • static types
    • immutability
    • pure function
  3. 以搜尋字串來舉例,看看下列的實作,哪一個比較容易預測?哪一個容易理解?

    • clojure 的實作:不保証程式會停。
    • re-find 的實作:保証一定會停。
    • RE2/J 的實作:會停而且只使用 linear 的時間。
  4. 愈 powerful 的解法,就愈不 predicatable。

    • With great power comes with great unpredicatability.
  5. Rule of least power

DSL

  1. literal map Clojure literal map can be used to define function with a single argument and small domain.
  2. destructure

DSL used in routing

  1. compojure
  2. yada

DSL used in queries

  1. Datomic
  2. graphQL

DSL used in framework

  1. integrant

rules of thumb for creating constrained DSL

  1. Avoid loops and recursion (= avoid turing complete)
  2. Look for matching and destructuring
  3. Look for static structure
  4. Make use of :namespaced/keyword
    • namespaced/keyword 可以繼承
  5. Make use of diffearent types
    • 利用 type 來做 case statement
  6. Make use of spec for complex grammars

從 predictable 與 powerful 的角度來思考

Clojure 有三種實作類似 function semantics 的方式:

  1. literal map
  2. defn
  3. macro
  • 方法一,最 predictable 也最 limited 。
  • 方法三,最 powerful 同時也最 unpredictable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment