The document discusses the productivity benefits of Clojure, including REPL-driven development, immutable data structures, functional programming, and the immutable Datomic database. REPL-driven development allows writing and testing code incrementally. Immutable data structures and functional programming eliminate the need for deep cloning and enable better function composability. The immutable Datomic database allows "time travel" queries on historical data without additional tables. In summary, Clojure offers improvements to test-driven development, data handling, and database queries through these features.
3. Motivation behind this talk
● 2019 Stackoverflow survey: Clojure programmers get highest salary
● But, in Taiwan
You will find no job if you tell your boss that you want to use Clojure.
4. Most important reasons to love Clojure from survey
● Lisp & REPL-driven development
● Immutable data structures/Functional programming
● JVM & Java interoperation
11. Areas of improvement
1. Can we get immediate feedback?
2. Can we write and test incrementally?
3. Can we test even smallest unit? For example,
single expression or statement?
12. Editor which can judge the
boundry of s-expression.
REPL-driven development
Write test argument in Editor
Write source code in Editor
Clojure REPL
Send source/test to
REPL
Get result back
23. Editor integration and semantic editing
● cqp => Evalute at the prompt
● cpp => Evaluate the current expression
● :Require => reload the whole file
● [ d => jump to definition
● > ) => slurp
● < ) => barf
● cseb => surround the current element with parentheses
● dsf => delete surrounding parentheses
25. Q & A
● How much productivity improvement will you have from
REPL-driven development? at least 30%
● Can REPL-driven programming be used in other
programming languages? Yes, but ...
● Can macro (meta-programming) be used in other
programming languages? Yes, but ...
27. You need `_.cloneDeep()` at javascript
var a = [1, 2, 3]
a.flatMap(z => [z, z+3]) => return value is [1, 4, 2, 5, 3, 6]
var b = [{x: 1}, {x: 2}, {x: 3}]
var c = b.flatMap(z => [z, z[“x”]]) => c is [{x: 1}, 1, {x: 2}, 2, {x: 3}, 3]
c[0][“x”] = 6; => b is [{x: 6}, {x: 2}, {x: 3}]
28. Functional programming dilemma
● Passing data by value
○ Guarantee that any changes will only affect local scope.
○ Extremely inefficient
● Passing data by reference
○ Save memory/Fast
○ Code is more difficult to reason about
○ Not safe at multi-thread environment
30. There is no `cloneDeep` in Clojure
● Garbage collection => obsoletes `delete` (Manually track
memory allocation/deallocation)
● Immutable data structure => obsoletes `cloneDeep`
(Manually manage data references)
31. Function composability in JavaScript is not good
Object/Map
Array
Functions defined on
Object/Map
Functions defined on Array
??
36. Q & A
● How much productivity improvement will you have from
immutable data structures and composable functions?
at least 30%
● Can immutable data structures and composable functions
be used in browser? Yes, ClojureScript
39. temporal database queries
Orders/ Orders
history
Excel filesdaily ETL
I want to know the
revene data today.
I want to know the revenue
data last week.
40. Immutable database allows time traveling
● orders history table is the analogy of
`_.cloneDeep`
● In Datomic, you only need orders table and
`(as-of db t)`
● SQL:2011 also support temporal databases
● PostgreSQL has temporal_tables extensions
41. Conclusion
● You can have better Test-driven development.
● You can forget _.cloneDeep().
● You can have better function composability.
● You can have immutable database.