Slides from Railscamp Germany 2014.
View the presentation here: https://dl.dropboxusercontent.com/u/15321563/railscamp-2014-presentation/index.html
Press p
to switch to presenter mode and see my notes.
Here are the slides in markdown:
- Background: philosophy & English literature
- Rails, JavaScript at Railslove by day
- Increasingly more Clojure at night
Whet your appetite!
Too-good-to-be-true but also foreign
“Anyone could learn LISP in one day, except that if they already knew Fortran, it would take three days.” — Marvin Minsky
- introducing several new ideas at once
- not a tutorial, very little code
- aiming for breadth over in-depth
- Clojure (FP, LISP)
- Om (React, ClojureScript)
(unlike Java - JavaScript)
- modern LISP, good for FP]
- Rich Hickey's "Simplicity Matters"
- learn Clojure to gain better access to Rich's thinking
- great community
- "JavaScript MVC" in ClojureScript
- first steps in the browser
- tangible results in a familiar environment
-> I built a card game called "Omingard"
Photos of David Nolen and Rich Hickey © and courtesy of Mike Bridge. Sources: David, Rich.
LISP: 1958; Fortran 1956 List Processing
Clojure: like Ruby, a general-purpose programming language, 2007
Om: ClojureScript interface for React; "JavaScript MVC"; last December
(+ 1 1)
“Lisp is a programmable programming language.” — John Foderaro
-
Ruby:
3 * 4 + 7
-
Clojure:
(+ 7 (* 3 4))
-
homoiconicity: code has same structure as the abstract syntax tree
-
in Ruby this isn't the case; interpreter has to know about operator precedence and so do you
(+ 1 1)
- Code is data: the code above is a list
- When writing macros, code can be manipulated like any other data - you can call functions like
map
on it etc.
- pragmatic versus academic (Haskell)
- dynamic
- impurely functional (you can mutate special reference types - e.g. atoms)
- runs on:
- the JVM (Clojure)
- JavaScript engines (ClojureScript)
-
LISP
-
embraces immutability & values
- good for concurrency
-
immutability is widely seen as the more important one!
- is written in Java
- compiles Clojure code to Java bytecode
- compiles a subset of Clojure code to JavaScript
- subset: single thread, can't do some Clojure stuff
- we treat them as one language here targeting two platforms - Java doesn't run everywhere after all :)
- has Clojure semantics
- Clojure compilation contains more than CoffeeScript compilation, since it remodels Clojure data structures in JavaScript
- simplicity (Clojure)
- trees / immutable persistent data structures (Clojure)
- React's virtual DOM
- power of immutable data structures
- global app state
- (core.async) - not covered :(
"We can make the same exact software we are making today with dramatically simpler stuff. Radically simpler than Ruby, which seems really simple. Why aren't we?"
Rich Hickey. 2012. "Simplicity matters".
If there's one thing to take away from this talk then it's to watch this talk.
"Simple is the opposite of complex. A thing is simple if it has no interleaving, if it has one purpose, one concept, one dimension, one task.
Being simple does not imply one instance or one operation: it's about interleaving, not cardinality. Importantly, this means that simplicity is objective."
Rich Hickey. "Simple made easy".
Easy is the opposite of hard, or difficult. A thing is easy if it's near to hand, if it's easy to get at (location), if it's near to our understanding (familiarity) [...] This means that ease is relative.
Rich Hickey. "Simple made easy".
"Speaking English is dead easy for me, but that doesn't mean that speaking English is intrinsically simple. I find French quite difficult. Little French children speak French all the time, [...] It's easy for them, it lies near to them."
Rich Hickey. "Simple made easy".
- opposite of complex (braided, interwoven)
- about one thing
- objective
- opposite of hard
- relative
- easy for me -vs- easy for you
-
mistake easy for simple things
-
gem install hairball
-
German: einfach (simple) -vs- leicht (easy)
- syntax - data
- state, objects - values
- ORM - unadorned data
"Simplicity Matters"
(http://youtu.be/rI8tNMsozo0?t=21m41s)
- functions never modify their arguments - but return copies
(clojure.string/upper-case "MiXeD cAsE")
- Ruby mutable hashes, arrays, strings etc.
x = "MiXeD cAsE"
x.upcase!
=> "MIXED CASE"
x
=> "MIXED CASE" # (same object_id)
-
thank God there's normal
upcase
as well, so mutation is not the default, but it's possible. And we mutate arrays or hashes all over the place. -
Clojure: immutable. Easier-to-reason-about applications.
-
(atoms: mutable, but the REF - not the function/method decides whether mutation takes place)
(def my_vec '( 1 2 3 4 ))
=> #'user/my_vec
(conj (pop my_vec) 11) ;; remove first el, add 11 to front
=> (11 2 3 4)
(-> my_vec ;; threading macro
pop
(conj 11))
=> (11 2 3 4)
my_vec
=> (1 2 3 4)
- Works like git, only small diffes are kept to create second vector.
- important for Om
- Buckle your seatbelt.
- There will be a lot more details on this in the upcoming blog post!
- "JavaScript MVC"
-
normal JS-MVC:
data -> templates -> DOM -
React: data -> templates -> virtual DOM -> DOM
-
data: models, JSON
-
templates: handlebars etc.
- VDOM is a plain JS object
- data changes, templates get rerendered
- new VDOM gets DIFFed with old one
- minimal set of actual DOM updates calculated
- change a user's name that's displayed in several Views on the page: all these views get rerendered entirely
-
if any part of our app's data changes, we can just rerender EVERYTHING.
-
frameworks like Ember do a lot for you behind the scenes to remain performant and make your life easier (remember simplicity!?) - React is just way simpler than that.
-
Om benefits from ClojureScript's immutable data structures
-
even faster diffing
-
faster diffing: only reference equality checks -vs- traversing the entire JSON structure.
- global app state
- undo in 13 lines of code
- not a memory problem b/c our persistent data structures use structural sharing.
http://tinyurl.com/clojureverse
- Programming inside a Database - "Thinking Outside the Loop" - Chris Granger @ thoughtbot podcast http://podcasts.thoughtbot.com/giantrobots/111 programming inside a database
- Urbit: http://alexkrupp.typepad.com/sensemaking/2013/12/a-brief-introduction-to-urbit.html
- Rich Hickey. "Simplicity matters". Rails Conf. 2012. http://tinyurl.com/simplicity-matters.
ClojureScript:
-
Geekstammtisch Moritz Heidkamp - "Vom Tellerwäscher zum LISP-Entwickler"]
CSP & core.async:
- Webinar: Designing Front End Applications with core.async
- Communicating sequential processes
- Make no promises - David Nolen
- Implementation details of core.async Channels - Rich Hickey