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 brought by Clojure

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 brought by Clojure (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

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 

Recently uploaded (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

The productivity brought by Clojure

  • 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