SlideShare a Scribd company logo
1 of 72
Download to read offline
Down the (Clojure) 
Rabbit Hole 
FP Days 2014 
@cgrand
Who am I? 
• Independent software dev 
• Early adopter (6+ years) 
• Authored a couple of libs 
• Co-authored Clojure Programming
Where I come from 
• Growing pains: Logo, 8-bit BASIC, Assembly, 
Pascal, C/C++ 
• Enlightenment: Caml Light 
• Dark ages: Entreprise Java
A New Hope 
• Wait, there’s more to Javascript than copy-pasting 
incantations!? 
• 1st class functions? Party on!
It can’t go wrong… 
• Concurrent server-side Javascript 
• Left me with a lot of cicatricial tissue
Wish list 
• Functional 
• Dynamic 
• JVM 
• Meta-programming 
• Concurrency story
Wish list 
✓ Functional 
✓ Dynamic 
✓ JVM 
✓ Meta-programming 
✓ Concurrency story
When the pupil is ready 
to learn, 
a teacher will appear.
A B
A B
A B
A B
Parentheses!
Pragmatic Parentheses! 
• Don’t commit to a syntax 
• Don’t spend time budget on syntax 
• Open to extension 
• Metaprogramming and serialization for free!
Immutability
Persistent Data Structures 
• More than immutable 
• Want! for years 
• But didn’t know the word to look for
What is immutable 
with log ops?
Numbers!
Okasaki and base-10 cubes 
• Persistent Data Structures as 
numeral systems 
• Base-10 cubes
Collections as numbers 
• inc is cons 
• random access 
list 
• log 472 
• elementary 
school material!
Data structures for free 
• Devise a twisted numeral system (no zero, extra 
digits, ambiguous, etc.) 
• Get a persistent data structure for free!
ROMANA 
DATASTRVCTVRA
Strict 2-3 Finger Trees 
• 4 digits: 0, 1, 2, 3 
• Positional AND symmetric 
• 2n+1 digits 
• dk, k ≤ n has weight 2k, k ≥ n has weight 22n-k 
• 0 and 1 only allowed for the most significant digit
Inc by the right 
0 
1 
2 
3 
202 
203 
212 
213 
222 
223 
232 
233 
22022 
22023 
22032 
22033 
22122 
22123
Dec by the left 
22123 
33023 
23023 
32023 
22023 
333 
233 
323 
223 
313 
213 
303 
203 
202 
3 
2 
1 
0
Back to data
Dynamic + Persistent 
• Low ceremony modeling: 
• easily map external data to internal values 
• 1:1 most of the time 
• one model end-to-end 
• or several identical ones…
Evolution 
• As you gain knowledge 
• Introduce layers 
• Recursive process 
• Models for each layer may diverge 
• Converters are enough 
• Must Ignore semantics
Loose Coupling 
• Sharing values ≠ sharing mutable objects 
• Sharing schemas ≠ sharing classes 
• Coupling is caused by behavior and mutability 
• Dumber is better
Who Needs Encapsulation? 
• When things can’t change, why continuously check 
invariants? 
• Use validators to enforce invariants 
• Safe publication 
• How a value is built is of no importance
Beware of Postel’s Law 
Be conservative in what you send, be liberal in what 
you accept. 
This defines de facto validity 
Hard to reverse-engineer, not declarative enough
Modularity 
• Easily serializable values (map, vectors etc.) 
• Low coupling 
• Allows for an easier transition from internal module 
to external service
Data as API
Data as API 
• Blind spots 
• process must be agreed upon out of band 
• process is closed 
• coupling to a version of the process 
• Bring objects and behavior back!
Who needs objects? 
• We have closures! (or the other way round) 
• Let’s put closures in the map! 
• But closures don’t print! 
• Pesky behaviors…
How do you call a system 
that sends data and 
process in-band?
A web server!
Data+Process=HTML 
• Content is data 
• Links and forms define processes 
• Javascript too but is beyond the Turing horizon
Anatomy of a Form 
<form action="http://example.org/xyz" method=post> 
<input type=hidden name=secret value="0xDECAF"> 
<label>First name: <input name=fname></label> 
</form>
Anatomy of a Form 
Function pointer 
<form action="http://example.org/xyz" method=post> 
<input type=hidden name=secret value="0xDECAF"> 
<label>First name: <input name=fname></label> 
</form>
Anatomy of a Form 
Function pointer 
Invocation 
Protocol 
impl. 
<form action="http://example.org/xyz" method=post> 
<input type=hidden name=secret value="0xDECAF"> 
<label>First name: <input name=fname></label> 
</form>
Anatomy of a Form 
Function pointer 
Invocation 
Protocol 
impl. 
<form action="http://example.org/xyz" method=post> 
<input type=hidden name=secret value="0xDECAF"> 
<label>First name: <input name=fname></label> 
</form> 
Closed over 
environment
A form is a closure!
Hypermedia API? 
• Cambrian explosion (HAL, Siren, Uber…) but no 
uptake 
• A good starting point may be to look at closures 
that are good form candidates 
• named arguments 
• partials 
• arguments shuffling/renaming
What’s to be gained? 
• Not only you get data as usual 
• That you can manipulate as you wish from your 
side of the fence 
• But you also get dynamic introspection of the other 
side!
Let’s pretend it exists 
{:todos 
[{:desc "Invoice Client XXX" 
:mark-as-done (form-inspired-serialization-goes-here) 
:delete (form-inspired-serialization-goes-here)} 
{:desc "Work on Enliven" 
:mark-as-done (form-inspired-serialization-goes-here) 
:delete (form-inspired-serialization-goes-here)}] 
:create (form-inspired-serialization-goes-here)} 
• all closures are lifted out of the data and mapped 
by names to generic functions 
• names should be namespaced and shared
Benefits 
• Coupling between producer and consumer is now 
only an agreements on names and schemas 
• The process is dynamic 
• REPL experience 
• Worth exploring: closures as arguments
Abusive Simplifications 
• Using closure for endpoint is an abuse 
• HTTP or synchronicity are not required 
• May apply to a messaging system 
• as long as some fns are adressable
Computation
Sequences 
• Iteration model 
• Should not be confused with collections 
• or only very locally 
• The (original) way to compose computations
Indices are a smell 
• Indices may look efficient 
• but that’s only because we picked data structures 
for which they are
Pet peeve: strings 
• Strings as chunks of 16 bits chars 
• Waste of space because many code points < 256 
• chars are not even characters… 
• Forces you to copy and decode bytes to chars
Pet peeve: strings 
• An abstraction with cursors (local moves/searches) 
but no indexed lookup 
• Would allow to deal with encoded UTF-8 directly 
• AFAIK all algorithms that requires indexed lookup 
(eg Boyer Moore) could work on bytes and be 
composed with encoding
Enliven 
• Work in progress templating library 
• I explored composing the encoding with the 
template: static parts are precomputed as bytes, 
possibly in direct ByteBuffers 
• I even tried composing with gzip
GZON 
• Directly emits compressed JSON 
• Avoids repeated conversions and writes of 
commons expressions (constants, field names, 
templates values) 
• Avoids having to find repetitions right after having 
emitted them 
• Coming to Github soon
Towards Efficiency 
• By avoiding unnecessary copies and allocations 
• By composing/merging computations
In Clojure too 
• Sequences 
• Chunked sequences 
• Reducers 
• Transducers
Efficiency perspectives 
• GPUs 
• Cache-Oblivious data structures
Ordering considered 
harmful
Ordering 
• Incidental vs Essential 
• Incidental ordering breaks local reasoning 
• deeply nested ifs 
• short-circuiting and/or 
• pattern matching clauses
Short-circuiting and/or 
• Refactor with care! 
• Swapping two expressions may: 
• Cause exceptions 
(and (not= x 0) (/ 1 x)) 
• Change the returned value 
(and (pred x) (lookup x))
Short-circuiting and/or 
• You can’t know when order matters 
• The compiler can’t either
Regexes 
=> (re-seq #"a|ab" "abababab") 
("a" "a" "a" "a") 
• Choice is ordered 
• You can’t locally fix a regex
CFG vs RDP 
• L ::= "a" L "a" | "a" 
• Which strings are matched?
CFG vs RDP 
• L ::= "a" L "a" | "a" 
• Which strings are matched? 
• CFG: any string of 2N+1 "a"s 
• RDP: any string of 2^N-1 "a"s
CFG vs RDP 
• L ::= "a" | "a" L "a" 
• Which strings are matched?
CFG vs RDP 
• L ::= "a" | "a" L "a" 
• Which strings are matched? 
• CFG: any string of 2N+1 "a"s 
• RDP: just "a"
miniKanren/core.logic 
• Depending on the ordering of your disjunctions and 
conjunctions... 
• ...your program may run endlessly without ever 
returning a single answer 
• Defaults fixed for disjunction in the draft of the 
Reasoned Schemer 2nd edition and in core.logic 
• Fair conjunction is harder 
• ASP (Answer Set Programming) is really pure
ACId is declarative 
• Associative 
• Ordering is not execution 
• Commutative 
• Accidental ordering should not matter 
• Idempotent 
• Factorisation as an optimisation
ACId in practice 
• I designed Enliven following ACId principles 
• Easier to reason about a template than with Enlive 
• Way faster: as fast as print 
• Point-free
Misc 
• Local state is the danger, global state is fine 
• Nano VMs are fun
Thanks!

More Related Content

What's hot

Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml MappingMarc Seeger
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...Gianluca Padovani
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with AkkaNgoc Dao
 
Serialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsSerialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsAlex Tumanoff
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptRangana Sampath
 
Serialization (Avro, Message Pack, Kryo)
Serialization (Avro, Message Pack, Kryo)Serialization (Avro, Message Pack, Kryo)
Serialization (Avro, Message Pack, Kryo)오석 한
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Invitation to the dark side of Ruby
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of RubySATOSHI TAGOMORI
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and ClassesMichael Heron
 
Functional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerFunctional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerLuis Atencio
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object OrientationMichael Heron
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Haim Yadid
 
Actor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupActor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupApcera
 
Persistent Data Structures And Managed References
Persistent Data Structures And Managed ReferencesPersistent Data Structures And Managed References
Persistent Data Structures And Managed ReferencesMichael Galpin
 

What's hot (20)

cb streams - gavin pickin
cb streams - gavin pickincb streams - gavin pickin
cb streams - gavin pickin
 
Ruby Xml Mapping
Ruby Xml MappingRuby Xml Mapping
Ruby Xml Mapping
 
David buksbaum a-briefintroductiontocsharp
David buksbaum a-briefintroductiontocsharpDavid buksbaum a-briefintroductiontocsharp
David buksbaum a-briefintroductiontocsharp
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with Akka
 
Serialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsSerialization and performance by Sergey Morenets
Serialization and performance by Sergey Morenets
 
jTransfo quickie at JavaZone 2015
jTransfo quickie at JavaZone 2015jTransfo quickie at JavaZone 2015
jTransfo quickie at JavaZone 2015
 
Recent nlp trends
Recent nlp trendsRecent nlp trends
Recent nlp trends
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon2018 12-kube con-ballerinacon
2018 12-kube con-ballerinacon
 
Serialization (Avro, Message Pack, Kryo)
Serialization (Avro, Message Pack, Kryo)Serialization (Avro, Message Pack, Kryo)
Serialization (Avro, Message Pack, Kryo)
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Invitation to the dark side of Ruby
Invitation to the dark side of RubyInvitation to the dark side of Ruby
Invitation to the dark side of Ruby
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Maccro Strikes Back
Maccro Strikes BackMaccro Strikes Back
Maccro Strikes Back
 
Functional programming for the Advanced Beginner
Functional programming for the Advanced BeginnerFunctional programming for the Advanced Beginner
Functional programming for the Advanced Beginner
 
CPP13 - Object Orientation
CPP13 - Object OrientationCPP13 - Object Orientation
CPP13 - Object Orientation
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
Actor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupActor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder Meetup
 
Persistent Data Structures And Managed References
Persistent Data Structures And Managed ReferencesPersistent Data Structures And Managed References
Persistent Data Structures And Managed References
 

Similar to FP Days: Down the Clojure Rabbit Hole

Stig: Social Graphs & Discovery at Scale
Stig: Social Graphs & Discovery at ScaleStig: Social Graphs & Discovery at Scale
Stig: Social Graphs & Discovery at ScaleDATAVERSITY
 
ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019Rory Graves
 
Data Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture PatternsData Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture PatternsHuahai Yang
 
Killing Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORMKilling Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORMOrtus Solutions, Corp
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Jon Haddad
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and AbstractionsMetosin Oy
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012Eonblast
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInLinkedIn
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living DatalogMike Fogus
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015Ben Lesh
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDavide Mauri
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQLDon Demcsak
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationAndrew Siemer
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Don Demcsak
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxsandeshshahapur
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with EpsilonSina Madani
 
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)Bob Pusateri
 

Similar to FP Days: Down the Clojure Rabbit Hole (20)

Voldemort Nosql
Voldemort NosqlVoldemort Nosql
Voldemort Nosql
 
Stig: Social Graphs & Discovery at Scale
Stig: Social Graphs & Discovery at ScaleStig: Social Graphs & Discovery at Scale
Stig: Social Graphs & Discovery at Scale
 
ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019ScalaClean at ScalaSphere 2019
ScalaClean at ScalaSphere 2019
 
Data Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture PatternsData Diffing Based Software Architecture Patterns
Data Diffing Based Software Architecture Patterns
 
Killing Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORMKilling Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORM
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012VoltDB and Erlang - Tech planet 2012
VoltDB and Erlang - Tech planet 2012
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedInJay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
 
The Return of the Living Datalog
The Return of the Living DatalogThe Return of the Living Datalog
The Return of the Living Datalog
 
RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015RxJS and Reactive Programming - Modern Web UI - May 2015
RxJS and Reactive Programming - Modern Web UI - May 2015
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
Introduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregationIntroduction to CQRS - command and query responsibility segregation
Introduction to CQRS - command and query responsibility segregation
 
How to choose a database
How to choose a databaseHow to choose a database
How to choose a database
 
CPP19 - Revision
CPP19 - RevisionCPP19 - Revision
CPP19 - Revision
 
Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)Big Data (NJ SQL Server User Group)
Big Data (NJ SQL Server User Group)
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Distributed Model Validation with Epsilon
Distributed Model Validation with EpsilonDistributed Model Validation with Epsilon
Distributed Model Validation with Epsilon
 
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
 

Recently uploaded

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 

Recently uploaded (20)

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 

FP Days: Down the Clojure Rabbit Hole

  • 1. Down the (Clojure) Rabbit Hole FP Days 2014 @cgrand
  • 2. Who am I? • Independent software dev • Early adopter (6+ years) • Authored a couple of libs • Co-authored Clojure Programming
  • 3. Where I come from • Growing pains: Logo, 8-bit BASIC, Assembly, Pascal, C/C++ • Enlightenment: Caml Light • Dark ages: Entreprise Java
  • 4. A New Hope • Wait, there’s more to Javascript than copy-pasting incantations!? • 1st class functions? Party on!
  • 5. It can’t go wrong… • Concurrent server-side Javascript • Left me with a lot of cicatricial tissue
  • 6. Wish list • Functional • Dynamic • JVM • Meta-programming • Concurrency story
  • 7. Wish list ✓ Functional ✓ Dynamic ✓ JVM ✓ Meta-programming ✓ Concurrency story
  • 8. When the pupil is ready to learn, a teacher will appear.
  • 9. A B
  • 10. A B
  • 11. A B
  • 12. A B
  • 14. Pragmatic Parentheses! • Don’t commit to a syntax • Don’t spend time budget on syntax • Open to extension • Metaprogramming and serialization for free!
  • 16. Persistent Data Structures • More than immutable • Want! for years • But didn’t know the word to look for
  • 17. What is immutable with log ops?
  • 19. Okasaki and base-10 cubes • Persistent Data Structures as numeral systems • Base-10 cubes
  • 20. Collections as numbers • inc is cons • random access list • log 472 • elementary school material!
  • 21. Data structures for free • Devise a twisted numeral system (no zero, extra digits, ambiguous, etc.) • Get a persistent data structure for free!
  • 23. Strict 2-3 Finger Trees • 4 digits: 0, 1, 2, 3 • Positional AND symmetric • 2n+1 digits • dk, k ≤ n has weight 2k, k ≥ n has weight 22n-k • 0 and 1 only allowed for the most significant digit
  • 24. Inc by the right 0 1 2 3 202 203 212 213 222 223 232 233 22022 22023 22032 22033 22122 22123
  • 25. Dec by the left 22123 33023 23023 32023 22023 333 233 323 223 313 213 303 203 202 3 2 1 0
  • 27. Dynamic + Persistent • Low ceremony modeling: • easily map external data to internal values • 1:1 most of the time • one model end-to-end • or several identical ones…
  • 28. Evolution • As you gain knowledge • Introduce layers • Recursive process • Models for each layer may diverge • Converters are enough • Must Ignore semantics
  • 29. Loose Coupling • Sharing values ≠ sharing mutable objects • Sharing schemas ≠ sharing classes • Coupling is caused by behavior and mutability • Dumber is better
  • 30. Who Needs Encapsulation? • When things can’t change, why continuously check invariants? • Use validators to enforce invariants • Safe publication • How a value is built is of no importance
  • 31. Beware of Postel’s Law Be conservative in what you send, be liberal in what you accept. This defines de facto validity Hard to reverse-engineer, not declarative enough
  • 32. Modularity • Easily serializable values (map, vectors etc.) • Low coupling • Allows for an easier transition from internal module to external service
  • 34. Data as API • Blind spots • process must be agreed upon out of band • process is closed • coupling to a version of the process • Bring objects and behavior back!
  • 35. Who needs objects? • We have closures! (or the other way round) • Let’s put closures in the map! • But closures don’t print! • Pesky behaviors…
  • 36. How do you call a system that sends data and process in-band?
  • 38. Data+Process=HTML • Content is data • Links and forms define processes • Javascript too but is beyond the Turing horizon
  • 39. Anatomy of a Form <form action="http://example.org/xyz" method=post> <input type=hidden name=secret value="0xDECAF"> <label>First name: <input name=fname></label> </form>
  • 40. Anatomy of a Form Function pointer <form action="http://example.org/xyz" method=post> <input type=hidden name=secret value="0xDECAF"> <label>First name: <input name=fname></label> </form>
  • 41. Anatomy of a Form Function pointer Invocation Protocol impl. <form action="http://example.org/xyz" method=post> <input type=hidden name=secret value="0xDECAF"> <label>First name: <input name=fname></label> </form>
  • 42. Anatomy of a Form Function pointer Invocation Protocol impl. <form action="http://example.org/xyz" method=post> <input type=hidden name=secret value="0xDECAF"> <label>First name: <input name=fname></label> </form> Closed over environment
  • 43. A form is a closure!
  • 44. Hypermedia API? • Cambrian explosion (HAL, Siren, Uber…) but no uptake • A good starting point may be to look at closures that are good form candidates • named arguments • partials • arguments shuffling/renaming
  • 45. What’s to be gained? • Not only you get data as usual • That you can manipulate as you wish from your side of the fence • But you also get dynamic introspection of the other side!
  • 46. Let’s pretend it exists {:todos [{:desc "Invoice Client XXX" :mark-as-done (form-inspired-serialization-goes-here) :delete (form-inspired-serialization-goes-here)} {:desc "Work on Enliven" :mark-as-done (form-inspired-serialization-goes-here) :delete (form-inspired-serialization-goes-here)}] :create (form-inspired-serialization-goes-here)} • all closures are lifted out of the data and mapped by names to generic functions • names should be namespaced and shared
  • 47. Benefits • Coupling between producer and consumer is now only an agreements on names and schemas • The process is dynamic • REPL experience • Worth exploring: closures as arguments
  • 48. Abusive Simplifications • Using closure for endpoint is an abuse • HTTP or synchronicity are not required • May apply to a messaging system • as long as some fns are adressable
  • 50. Sequences • Iteration model • Should not be confused with collections • or only very locally • The (original) way to compose computations
  • 51. Indices are a smell • Indices may look efficient • but that’s only because we picked data structures for which they are
  • 52. Pet peeve: strings • Strings as chunks of 16 bits chars • Waste of space because many code points < 256 • chars are not even characters… • Forces you to copy and decode bytes to chars
  • 53. Pet peeve: strings • An abstraction with cursors (local moves/searches) but no indexed lookup • Would allow to deal with encoded UTF-8 directly • AFAIK all algorithms that requires indexed lookup (eg Boyer Moore) could work on bytes and be composed with encoding
  • 54. Enliven • Work in progress templating library • I explored composing the encoding with the template: static parts are precomputed as bytes, possibly in direct ByteBuffers • I even tried composing with gzip
  • 55. GZON • Directly emits compressed JSON • Avoids repeated conversions and writes of commons expressions (constants, field names, templates values) • Avoids having to find repetitions right after having emitted them • Coming to Github soon
  • 56. Towards Efficiency • By avoiding unnecessary copies and allocations • By composing/merging computations
  • 57. In Clojure too • Sequences • Chunked sequences • Reducers • Transducers
  • 58. Efficiency perspectives • GPUs • Cache-Oblivious data structures
  • 60. Ordering • Incidental vs Essential • Incidental ordering breaks local reasoning • deeply nested ifs • short-circuiting and/or • pattern matching clauses
  • 61. Short-circuiting and/or • Refactor with care! • Swapping two expressions may: • Cause exceptions (and (not= x 0) (/ 1 x)) • Change the returned value (and (pred x) (lookup x))
  • 62. Short-circuiting and/or • You can’t know when order matters • The compiler can’t either
  • 63. Regexes => (re-seq #"a|ab" "abababab") ("a" "a" "a" "a") • Choice is ordered • You can’t locally fix a regex
  • 64. CFG vs RDP • L ::= "a" L "a" | "a" • Which strings are matched?
  • 65. CFG vs RDP • L ::= "a" L "a" | "a" • Which strings are matched? • CFG: any string of 2N+1 "a"s • RDP: any string of 2^N-1 "a"s
  • 66. CFG vs RDP • L ::= "a" | "a" L "a" • Which strings are matched?
  • 67. CFG vs RDP • L ::= "a" | "a" L "a" • Which strings are matched? • CFG: any string of 2N+1 "a"s • RDP: just "a"
  • 68. miniKanren/core.logic • Depending on the ordering of your disjunctions and conjunctions... • ...your program may run endlessly without ever returning a single answer • Defaults fixed for disjunction in the draft of the Reasoned Schemer 2nd edition and in core.logic • Fair conjunction is harder • ASP (Answer Set Programming) is really pure
  • 69. ACId is declarative • Associative • Ordering is not execution • Commutative • Accidental ordering should not matter • Idempotent • Factorisation as an optimisation
  • 70. ACId in practice • I designed Enliven following ACId principles • Easier to reason about a template than with Enlive • Way faster: as fast as print • Point-free
  • 71. Misc • Local state is the danger, global state is fine • Nano VMs are fun