SlideShare uma empresa Scribd logo
1 de 71
Baixar para ler offline
Clojure
About me
• humble software engineer @allegro
• kung fu master in spare time
• Almost none of those thoughts are mine.
Presumably there are no new thoughts after
Aristotle. For sure after 1970…
What we think we are
doing?
Computer science
What do we do?
What do we really do?
What we really do
Meet Rich
Who
• Object Oriented?
• Functional Programming?
• What does it mean?
stolen 

from
Uncle

Bob
Async is everywhere
OO vs functional
Quiz
)}; )}; )}; )}; )}; )};
Most frequent code in JS
Most frequent code in Clojure
) ) ) ) ) ) ) )
First impressions
Quick intro to clojure
John McCarty
• Lisp
• interpreters
• high-level metaprogramming
• garbage collection
• dynamic programming
• functional programming
• programming with recursive
functions
• …
Quick intro to clojure
• f(x,y) -> (f x y)
• deleteOffer(2, :force) -> (delete-offer 2 :force)
function params
(def x 1) int x = 1;
(fn [x] (* x x)(def f ))
(f 5)
(defn f [x] (* x x))
Quick intro to clojure
• List

(1 2 3 4 5) (adrian krzychu wojtek) (list 1 2 3)
• Vectors

[1 2 3 4 5] [fred ethel lucy]
• Map 

{:a 1, :b 2, :c 3} {1 “ethel” 2 “fred}
• Sets

#{fred ethel lucy}
• Everything nested

Persistent data structure
Tail recursion
show some code!
(defn neighbours [[x y]]
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
[(+ dx x) (+ dy y)]))
(defn step [cells]
(set (for [[loc n] (frequencies (mapcat neighbours cells))
:when (or (= n 3) (and (= n 2) (cells loc)))]
loc)))
code from Christophe Grand
stolen from Rich Hickey
stolen from Rich Hickey
stolen from Rich Hickey
stolen from Rich Hickey
The same? Json
def builder = new groovy.json.JsonBuilder()
def root = builder.people {
person {
firstName 'Krzysztof'
lastName 'Kaczmarek'
}
}
(json {:person {
:firstName “Krzysztof”
:lastName “Kaczmarek”}})
Groovy Clojure
The same? Config
offerCoreStockService:
serviceAddress: service://offercore-stock-service
offerCoreService:
serviceAddress: service://offercore-service-server
{:offerCoreStockService
:serviceAddress “service://offercore-stock-service”
:offerCoreService
:serviceAddress “service://offercore-service-server”}
YML Clojure (edn)
The same?
– Greenspun's tenth rule
“Any sufficiently complicated C or Fortran
program contains an ad hoc, informally-
specified, bug-ridden, slow implementation of
half of Common Lisp.”
@RestController @EnableAutoConfiguration 

public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();


@RequestMapping("/greeting") public Greeting greeting(
@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.getAndIncrement(),
} }
String.format(template, name));
example provided by P. Kapała
@RestController @EnableAutoConfiguration 

public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();


@RequestMapping("/greeting") public Greeting greeting(
@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.getAndIncrement(),
} }
String.format(template, name));
example provided by P. Kapała
(def counter (atom 0))
(defn greet [target] 

{:id (swap! counter inc)
:name (str "Hello, " (or target "World") "!")})
(defroutes app-routes 

(GET "/greeting" {params :params}
(response (greet (:name params))))
(route/not-found "Not Found"))
example provided by P. Kapała
(def counter (atom 0))
(defn greet [target] 

{:id (swap! counter inc)
:name (str "Hello, " (or target "World") "!")})
(defroutes app-routes 

(GET "/greeting" {params :params}
(response (greet (:name params))))
(route/not-found "Not Found"))
example provided by P. Kapała
–-- Dr. Alan Kay, 2003.
“OOP to me means only messaging, local
retention and protection and hiding of state-
process, and extreme late-binding of all things. It
can be done in Smalltalk and in LISP. There are
possibly other systems in which this is possible,
but I'm not aware of them.”
–Rich Hickey
“Not everything is awesome.”
Fear - dynamic typing
Report createReport(Data data) {…}
vs
(create-report data)
Fear: Refactoring
Clojure w allegro
Success story?
• Simple rest service
• 2000 lines of code in java
• 150 lines of code in clojure (one 27” screen)
• most people exp: 1/5 of codebase
Java interop
(. Array new)
(. MyAwesomeService doJava “foo” “bar”)
Adoption
Last language?
ClojureScript
• Hosted
• Hello world => 2 LOC in JS
• Is it slow?
• Debugging
• > 2300 watchers
• 68 contributors
Clojure.async
• queues in app
• making app simpler to reason about
Clojure.async
First go
block
>! my queue <!
second go
block
How to learn
4clojure.org
Hype is coming
–Adrian Cockroft
“A lot of the best programmers and the most
productive programmers I know are writing
everything in Clojure and swearing by it, and
then just producing ridiculously sophisticated
things in a very short time. And that programmer
productivity matters. “
http://thenewstack.io/the-new-stack-makers-adrian-cockcroft-on-sun-netflix-clojure-
go-docker-and-more/
Q & A?
krzysztof.kaczmarek@me.com

Mais conteúdo relacionado

Mais procurados

Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Hiroki Mizuno
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
Mike Fogus
 

Mais procurados (20)

PyData Berlin Meetup
PyData Berlin MeetupPyData Berlin Meetup
PyData Berlin Meetup
 
The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88The Ring programming language version 1.3 book - Part 84 of 88
The Ring programming language version 1.3 book - Part 84 of 88
 
Full Stack Clojure
Full Stack ClojureFull Stack Clojure
Full Stack Clojure
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
 
CommonJS: JavaScript Everywhere
CommonJS: JavaScript EverywhereCommonJS: JavaScript Everywhere
CommonJS: JavaScript Everywhere
 
Stripe CTF3 wrap-up
Stripe CTF3 wrap-upStripe CTF3 wrap-up
Stripe CTF3 wrap-up
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
Garbage collector in python
Garbage collector in pythonGarbage collector in python
Garbage collector in python
 
Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発
 
ClojureScript: The Good Parts
ClojureScript: The Good PartsClojureScript: The Good Parts
ClojureScript: The Good Parts
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
Jakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheelJakarta Commons - Don't re-invent the wheel
Jakarta Commons - Don't re-invent the wheel
 
Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22Rust tutorial from Boston Meetup 2015-07-22
Rust tutorial from Boston Meetup 2015-07-22
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
 
Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»Леонид Шевцов «Clojure в деле»
Леонид Шевцов «Clojure в деле»
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
(Fun clojure)
(Fun clojure)(Fun clojure)
(Fun clojure)
 

Destaque

[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy
[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy
[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy
PROIDEA
 
4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow
4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow
4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow
PROIDEA
 
Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...
Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...
Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...
PROIDEA
 

Destaque (18)

[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy
[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy
[CONFidence 2016] Leszek Miś - Honey(pot) flavored hunt for cyber enemy
 
MCE^3 - C. Todd Lombardo - Organizational Dynamics of Innovation
MCE^3 - C. Todd Lombardo -  Organizational Dynamics of InnovationMCE^3 - C. Todd Lombardo -  Organizational Dynamics of Innovation
MCE^3 - C. Todd Lombardo - Organizational Dynamics of Innovation
 
4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow
4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow
4Developers 2015: Parę słów o odpowiedzialności projektanta UX - Igor Farafonow
 
Atmosphere 2016 - Justin arbuckle - A tale of the constructors
Atmosphere 2016 - Justin arbuckle  - A tale of the constructorsAtmosphere 2016 - Justin arbuckle  - A tale of the constructors
Atmosphere 2016 - Justin arbuckle - A tale of the constructors
 
[4developers2016] - Security in the era of modern applications and services (...
[4developers2016] - Security in the era of modern applications and services (...[4developers2016] - Security in the era of modern applications and services (...
[4developers2016] - Security in the era of modern applications and services (...
 
Konrad Kokosa - Pamięć w .NET - od ogólu do szczegółu- 4developers2016
Konrad Kokosa - Pamięć w .NET - od ogólu do szczegółu- 4developers2016Konrad Kokosa - Pamięć w .NET - od ogólu do szczegółu- 4developers2016
Konrad Kokosa - Pamięć w .NET - od ogólu do szczegółu- 4developers2016
 
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
MCE^3 - Jorge D. Ortiz - Fuentes - Escape From Mars
 
PLNOG14: Service orchestration in provider network, Tail-f - Przemysław Borek
PLNOG14: Service orchestration in provider network, Tail-f - Przemysław BorekPLNOG14: Service orchestration in provider network, Tail-f - Przemysław Borek
PLNOG14: Service orchestration in provider network, Tail-f - Przemysław Borek
 
Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...
Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...
Atmosphere Conference 2015: Building And Releasing A Massively Multiplayer On...
 
4Developers 2015: Refactoring za duże pieniądze, pierwsze kroki - Michał Gruca
4Developers 2015: Refactoring za duże pieniądze, pierwsze kroki - Michał Gruca4Developers 2015: Refactoring za duże pieniądze, pierwsze kroki - Michał Gruca
4Developers 2015: Refactoring za duże pieniądze, pierwsze kroki - Michał Gruca
 
PLNOG15: Virtualization and automation of network and security services in Da...
PLNOG15: Virtualization and automation of network and security services in Da...PLNOG15: Virtualization and automation of network and security services in Da...
PLNOG15: Virtualization and automation of network and security services in Da...
 
PLNOG 17 - Konrad Kulikowski - Cisco WAE - Wan Automation Engine - Co SDN moż...
PLNOG 17 - Konrad Kulikowski - Cisco WAE - Wan Automation Engine - Co SDN moż...PLNOG 17 - Konrad Kulikowski - Cisco WAE - Wan Automation Engine - Co SDN moż...
PLNOG 17 - Konrad Kulikowski - Cisco WAE - Wan Automation Engine - Co SDN moż...
 
PLNOG 17 - Marcin Aronowski - Technologie dostępowe dla IoT. Jak się w tym ws...
PLNOG 17 - Marcin Aronowski - Technologie dostępowe dla IoT. Jak się w tym ws...PLNOG 17 - Marcin Aronowski - Technologie dostępowe dla IoT. Jak się w tym ws...
PLNOG 17 - Marcin Aronowski - Technologie dostępowe dla IoT. Jak się w tym ws...
 
DOD 2016 - Sebastian Krzyszkowiak - Jenkins: The Pipeline
DOD 2016 - Sebastian Krzyszkowiak - Jenkins: The PipelineDOD 2016 - Sebastian Krzyszkowiak - Jenkins: The Pipeline
DOD 2016 - Sebastian Krzyszkowiak - Jenkins: The Pipeline
 
PLNOG 17 - Tomás Strašák - Latencja jest decydentem
PLNOG 17 - Tomás Strašák - Latencja jest decydentemPLNOG 17 - Tomás Strašák - Latencja jest decydentem
PLNOG 17 - Tomás Strašák - Latencja jest decydentem
 
infraxstructure: Stas Levitan, "Always On" business in cloud - 2016"
infraxstructure: Stas Levitan, "Always On" business in cloud - 2016"infraxstructure: Stas Levitan, "Always On" business in cloud - 2016"
infraxstructure: Stas Levitan, "Always On" business in cloud - 2016"
 
infraxstructure: Jarosław Zieliński i Sławomir Stanek "Wojna o Wirtualizację...
infraxstructure: Jarosław Zieliński i Sławomir Stanek  "Wojna o Wirtualizację...infraxstructure: Jarosław Zieliński i Sławomir Stanek  "Wojna o Wirtualizację...
infraxstructure: Jarosław Zieliński i Sławomir Stanek "Wojna o Wirtualizację...
 
PLNOG16: Microsoft Azure dla Inżynierów Sieciowych, Mirosław Burnejko
PLNOG16: Microsoft Azure dla Inżynierów Sieciowych, Mirosław BurnejkoPLNOG16: Microsoft Azure dla Inżynierów Sieciowych, Mirosław Burnejko
PLNOG16: Microsoft Azure dla Inżynierów Sieciowych, Mirosław Burnejko
 

Semelhante a Atmosphere 2016 - Krzysztof Kaczmarek - Don't fear the brackets - Clojure in the eyes of Java Developer

JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
Charles Nutter
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
Jan Kronquist
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Semelhante a Atmosphere 2016 - Krzysztof Kaczmarek - Don't fear the brackets - Clojure in the eyes of Java Developer (20)

Yin Yangs of Software Development
Yin Yangs of Software DevelopmentYin Yangs of Software Development
Yin Yangs of Software Development
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
 
Ruby is an Acceptable Lisp
Ruby is an Acceptable LispRuby is an Acceptable Lisp
Ruby is an Acceptable Lisp
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
Go 프로그래밍 소개 - 장재휴, DomainDriven커뮤니티
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
Carlo Sciolla - Above and beyond type systems with clojure.spec - Codemotion ...
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Scala clojure techday_2011
Scala clojure techday_2011Scala clojure techday_2011
Scala clojure techday_2011
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
Jose Selvi - Side-Channels Uncovered [rootedvlc2018]
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 
Clojure/conj 2017
Clojure/conj 2017Clojure/conj 2017
Clojure/conj 2017
 

Último

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
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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...
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Atmosphere 2016 - Krzysztof Kaczmarek - Don't fear the brackets - Clojure in the eyes of Java Developer

  • 2. About me • humble software engineer @allegro • kung fu master in spare time • Almost none of those thoughts are mine. Presumably there are no new thoughts after Aristotle. For sure after 1970…
  • 3. What we think we are doing? Computer science
  • 4.
  • 6. What do we really do?
  • 9.
  • 10.
  • 11. Who • Object Oriented? • Functional Programming? • What does it mean?
  • 12.
  • 14.
  • 17.
  • 18. Quiz )}; )}; )}; )}; )}; )}; Most frequent code in JS Most frequent code in Clojure ) ) ) ) ) ) ) )
  • 20.
  • 21. Quick intro to clojure
  • 22. John McCarty • Lisp • interpreters • high-level metaprogramming • garbage collection • dynamic programming • functional programming • programming with recursive functions • …
  • 23. Quick intro to clojure • f(x,y) -> (f x y) • deleteOffer(2, :force) -> (delete-offer 2 :force) function params
  • 24. (def x 1) int x = 1; (fn [x] (* x x)(def f )) (f 5) (defn f [x] (* x x))
  • 25. Quick intro to clojure • List
 (1 2 3 4 5) (adrian krzychu wojtek) (list 1 2 3) • Vectors
 [1 2 3 4 5] [fred ethel lucy] • Map 
 {:a 1, :b 2, :c 3} {1 “ethel” 2 “fred} • Sets
 #{fred ethel lucy} • Everything nested

  • 28.
  • 29.
  • 31. (defn neighbours [[x y]] (for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])] [(+ dx x) (+ dy y)])) (defn step [cells] (set (for [[loc n] (frequencies (mapcat neighbours cells)) :when (or (= n 3) (and (= n 2) (cells loc)))] loc))) code from Christophe Grand
  • 34.
  • 35.
  • 36.
  • 39. The same? Json def builder = new groovy.json.JsonBuilder() def root = builder.people { person { firstName 'Krzysztof' lastName 'Kaczmarek' } } (json {:person { :firstName “Krzysztof” :lastName “Kaczmarek”}}) Groovy Clojure
  • 40. The same? Config offerCoreStockService: serviceAddress: service://offercore-stock-service offerCoreService: serviceAddress: service://offercore-service-server {:offerCoreStockService :serviceAddress “service://offercore-stock-service” :offerCoreService :serviceAddress “service://offercore-service-server”} YML Clojure (edn)
  • 42. – Greenspun's tenth rule “Any sufficiently complicated C or Fortran program contains an ad hoc, informally- specified, bug-ridden, slow implementation of half of Common Lisp.”
  • 43.
  • 44. @RestController @EnableAutoConfiguration 
 public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); 
 @RequestMapping("/greeting") public Greeting greeting( @RequestParam(value="name", defaultValue="World") String name) { return new Greeting(counter.getAndIncrement(), } } String.format(template, name)); example provided by P. Kapała
  • 45. @RestController @EnableAutoConfiguration 
 public class GreetingController { private static final String template = "Hello, %s!"; private final AtomicLong counter = new AtomicLong(); 
 @RequestMapping("/greeting") public Greeting greeting( @RequestParam(value="name", defaultValue="World") String name) { return new Greeting(counter.getAndIncrement(), } } String.format(template, name)); example provided by P. Kapała
  • 46. (def counter (atom 0)) (defn greet [target] 
 {:id (swap! counter inc) :name (str "Hello, " (or target "World") "!")}) (defroutes app-routes 
 (GET "/greeting" {params :params} (response (greet (:name params)))) (route/not-found "Not Found")) example provided by P. Kapała
  • 47. (def counter (atom 0)) (defn greet [target] 
 {:id (swap! counter inc) :name (str "Hello, " (or target "World") "!")}) (defroutes app-routes 
 (GET "/greeting" {params :params} (response (greet (:name params)))) (route/not-found "Not Found")) example provided by P. Kapała
  • 48. –-- Dr. Alan Kay, 2003. “OOP to me means only messaging, local retention and protection and hiding of state- process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.”
  • 49.
  • 51. Fear - dynamic typing Report createReport(Data data) {…} vs (create-report data)
  • 54.
  • 55. Success story? • Simple rest service • 2000 lines of code in java • 150 lines of code in clojure (one 27” screen) • most people exp: 1/5 of codebase
  • 56. Java interop (. Array new) (. MyAwesomeService doJava “foo” “bar”)
  • 59. ClojureScript • Hosted • Hello world => 2 LOC in JS • Is it slow? • Debugging • > 2300 watchers • 68 contributors
  • 60. Clojure.async • queues in app • making app simpler to reason about
  • 61. Clojure.async First go block >! my queue <! second go block
  • 64.
  • 66. –Adrian Cockroft “A lot of the best programmers and the most productive programmers I know are writing everything in Clojure and swearing by it, and then just producing ridiculously sophisticated things in a very short time. And that programmer productivity matters. “ http://thenewstack.io/the-new-stack-makers-adrian-cockcroft-on-sun-netflix-clojure- go-docker-and-more/
  • 67.
  • 68.
  • 69.
  • 70.