SlideShare a Scribd company logo
1 of 43
Download to read offline
The productivity
brought by Clojure
Laurence Chen
http://twitter.com/humorless
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.
Most important reasons to love Clojure from survey
● Lisp & REPL-driven development
● Immutable data structures/Functional programming
● JVM & Java interoperation
Part One
● Clojure is a dialect of Lisp
● REPL-driven development
Lisp?
Lisp is a family of programming languages
1. CommonLisp
2. Scheme
3. Racket
4. Clojure
5. Hylang
6. Emacs Lisp - elisp
7. WASM - WebAssembly
S-expression v.s. M-expression
S-expression
● (fn x y)
● (+ a b)
M-expression
● fn(a, b)
● sort(colloection)
● Beating the average (超越平庸)
Test-driven development
● Edit test file
● Edit code file
● Run the program
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?
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
Demo
● Example Editor Command: cqp
● Evaluate at the prompt
Execution time measurement by cqp
Demo
● Example Editor Command: cpp
● Evaluate the current expression
Demo
● Example Editor Command: > )
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
Demo Time
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 ...
Part Two
● Immutable data structures
● Composable functions
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}]
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
Clojure immutable data structure: copy on write
There is no `cloneDeep` in Clojure
● Garbage collection => obsoletes `delete` (Manually track
memory allocation/deallocation)
● Immutable data structure => obsoletes `cloneDeep`
(Manually manage data references)
Function composability in JavaScript is not good
Object/Map
Array
Functions defined on
Object/Map
Functions defined on Array
??
R.map / R.mapObjIndexed
Collection <-> Sequence <-> Transformation library
Set
Map
Vector
List
Sequence
map, filter, reduce,
first, rest, mapcat,
apply, take, drop,
...
Lazy sequences,
strings,
Lines in a flie,
Files in a directory,
….
map/ into
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
Part Three
● Immutable database - Datomic
database queries
Orders
Excel filesdaily ETL
I want to know the
revene data today.
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.
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
Conclusion
● You can have better Test-driven development.
● You can forget _.cloneDeep().
● You can have better function composability.
● You can have immutable database.
● Thank you
● Q & A
Bibliography
1. stackoverflow survey 2019
2. xkcd.com/297 Lisp Cycles
3. Dmitri Sotnikov --- Clojure distilled
4. Rich Hickey --- “Clojure Concurrency” talk
5. Juan-Manuel Gimeno --- Functional programming in clojure

More Related Content

Similar to The Productivity Boost of Clojure's REPL, Immutability and Composability

Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Holden Karau
 
Scientific computing on jruby
Scientific computing on jrubyScientific computing on jruby
Scientific computing on jrubyPrasun Anand
 
Optimizing Performance - Clojure Remote - Nikola Peric
Optimizing Performance - Clojure Remote - Nikola PericOptimizing Performance - Clojure Remote - Nikola Peric
Optimizing Performance - Clojure Remote - Nikola PericNik Peric
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?Chuk-Munn Lee
 
Supervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemSupervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemMarsan Ma
 
FastR+Apache Flink
FastR+Apache FlinkFastR+Apache Flink
FastR+Apache FlinkJuan Fumero
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...Codemotion
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbMongoDB APAC
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextUnfold UI
 
Large-scale Recommendation Systems on Just a PC
Large-scale Recommendation Systems on Just a PCLarge-scale Recommendation Systems on Just a PC
Large-scale Recommendation Systems on Just a PCAapo Kyrölä
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab AlbanLevy
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowLaura Lorenz
 
A Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.pptA Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.pptSanket Shikhar
 
Bootstrapping state in Apache Flink
Bootstrapping state in Apache FlinkBootstrapping state in Apache Flink
Bootstrapping state in Apache FlinkDataWorks Summit
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Jonathan Felch
 
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...Flink Forward
 
Practical REPL-driven Development with Clojure
Practical REPL-driven Development with ClojurePractical REPL-driven Development with Clojure
Practical REPL-driven Development with ClojureKent Ohashi
 

Similar to The Productivity Boost of Clojure's REPL, Immutability and Composability (20)

Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
Ml pipelines with Apache spark and Apache beam - Ottawa Reactive meetup Augus...
 
Scientific computing on jruby
Scientific computing on jrubyScientific computing on jruby
Scientific computing on jruby
 
Data herding
Data herdingData herding
Data herding
 
Data herding
Data herdingData herding
Data herding
 
Optimizing Performance - Clojure Remote - Nikola Peric
Optimizing Performance - Clojure Remote - Nikola PericOptimizing Performance - Clojure Remote - Nikola Peric
Optimizing Performance - Clojure Remote - Nikola Peric
 
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
NUS Hackers Club Mar 21 - Whats New in JavaSE 8?
 
Supervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking systemSupervised embedding techniques in search ranking system
Supervised embedding techniques in search ranking system
 
FastR+Apache Flink
FastR+Apache FlinkFastR+Apache Flink
FastR+Apache Flink
 
JS Essence
JS EssenceJS Essence
JS Essence
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Buildingsocialanalyticstoolwithmongodb
BuildingsocialanalyticstoolwithmongodbBuildingsocialanalyticstoolwithmongodb
Buildingsocialanalyticstoolwithmongodb
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
Large-scale Recommendation Systems on Just a PC
Large-scale Recommendation Systems on Just a PCLarge-scale Recommendation Systems on Just a PC
Large-scale Recommendation Systems on Just a PC
 
Object Oriented Programming in Matlab
Object Oriented Programming in Matlab Object Oriented Programming in Matlab
Object Oriented Programming in Matlab
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
 
A Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.pptA Hands-on Intro to Data Science and R Presentation.ppt
A Hands-on Intro to Data Science and R Presentation.ppt
 
Bootstrapping state in Apache Flink
Bootstrapping state in Apache FlinkBootstrapping state in Apache Flink
Bootstrapping state in Apache Flink
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
Flink Forward San Francisco 2018: Gregory Fee - "Bootstrapping State In Apach...
 
Practical REPL-driven Development with Clojure
Practical REPL-driven Development with ClojurePractical REPL-driven Development with Clojure
Practical REPL-driven Development with Clojure
 

More from Laurence Chen

The obstacles of developer productivity.pptx
The obstacles of developer productivity.pptxThe obstacles of developer productivity.pptx
The obstacles of developer productivity.pptxLaurence Chen
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)Laurence Chen
 
On component interface
On component interfaceOn component interface
On component interfaceLaurence Chen
 
Schema, validation and generative testing
Schema, validation and generative testingSchema, validation and generative testing
Schema, validation and generative testingLaurence Chen
 
The immutable database datomic
The immutable database   datomicThe immutable database   datomic
The immutable database datomicLaurence Chen
 

More from Laurence Chen (7)

Create your library
Create your libraryCreate your library
Create your library
 
on log messages
on log messageson log messages
on log messages
 
The obstacles of developer productivity.pptx
The obstacles of developer productivity.pptxThe obstacles of developer productivity.pptx
The obstacles of developer productivity.pptx
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)
 
On component interface
On component interfaceOn component interface
On component interface
 
Schema, validation and generative testing
Schema, validation and generative testingSchema, validation and generative testing
Schema, validation and generative testing
 
The immutable database datomic
The immutable database   datomicThe immutable database   datomic
The immutable database datomic
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

The Productivity Boost of Clojure's REPL, Immutability and Composability

  • 1. The productivity brought by Clojure Laurence Chen http://twitter.com/humorless
  • 2.
  • 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
  • 5. Part One ● Clojure is a dialect of Lisp ● REPL-driven development
  • 7. Lisp is a family of programming languages 1. CommonLisp 2. Scheme 3. Racket 4. Clojure 5. Hylang 6. Emacs Lisp - elisp 7. WASM - WebAssembly
  • 8. S-expression v.s. M-expression S-expression ● (fn x y) ● (+ a b) M-expression ● fn(a, b) ● sort(colloection)
  • 9. ● Beating the average (超越平庸)
  • 10. Test-driven development ● Edit test file ● Edit code file ● Run the program
  • 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
  • 13. Demo ● Example Editor Command: cqp ● Evaluate at the prompt
  • 14.
  • 15.
  • 17. Demo ● Example Editor Command: cpp ● Evaluate the current expression
  • 18.
  • 19.
  • 20. Demo ● Example Editor Command: > )
  • 21.
  • 22.
  • 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 ...
  • 26. Part Two ● Immutable data structures ● Composable functions
  • 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
  • 29. Clojure immutable data structure: copy on write
  • 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 ??
  • 33. Collection <-> Sequence <-> Transformation library Set Map Vector List Sequence map, filter, reduce, first, rest, mapcat, apply, take, drop, ... Lazy sequences, strings, Lines in a flie, Files in a directory, ….
  • 34.
  • 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
  • 37. Part Three ● Immutable database - Datomic
  • 38. database queries Orders Excel filesdaily ETL I want to know the revene data today.
  • 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.
  • 43. Bibliography 1. stackoverflow survey 2019 2. xkcd.com/297 Lisp Cycles 3. Dmitri Sotnikov --- Clojure distilled 4. Rich Hickey --- “Clojure Concurrency” talk 5. Juan-Manuel Gimeno --- Functional programming in clojure