"I'll tell you what that is. That's an alien, brother. Believe it. Must have come from outer space, trying to take over Earth. But it landed in the wrong place - the wrong place!"
Paul Wittmann
@wakkahari
paul@railslove.com
7. Oktober 2014, Bochum
Railscamp Slides
- zu gut um wahr zu sein
- fremdartig
- Clojure
- Warum?
- Ideen dahinter
- Wo anfangen?
- Om
- unveränderbare Datenstrukturen & globaler Zustand, Undo, core.async
- Mehr:
- Overtone, Datomic, DataScript
- Grenzen von OOP, neugierig auf funktionale Programmierung und LISP.
- Clojure ist modern, aktive und nette Community, man kann Webapps mit bauen.
- Om als Türöffner in Clojure - im Browser kann ich anfassbare Sachen in vertrauter Umgebung bauen, die nicht so langweilig wie Programmierbuch-Beispiele sind.
- Nebeneffekt: Om & React sind interessante "JS-MVC" und alle anderen überzeugen mich bisher nicht.
- Blog Post "My Way into Clojure: Building a Card Game with Om" in Vorbereitung
- Rails Conf 2012 Keynote: Simplicity Matters by Rich Hickey
- Tim Ewald - Clojure: Programming with Hand Tools
- "The Future of JavaScript MVC Frameworks"
- Geekstammtisch mit Moritz Heidkamp - "Vom Tellerwäscher zum LISP-Entwickler"
- The Changelog: Rich Hickey's Greatest Hits
- LightTable statt Emacs, da ClojureScript Integration zwischen Editor und Browser viel leichter war - tutorial; demo
- Offizielles Om tutorial
- O'Reilly-Buch: Clojure Programming
- Cognitect Podcast: The Cognicast
- Clojure Gazette: wöchentlicher Newsletter
- 2007
- Rich Hickey
- Richs 4. Versuch eines gehosteten LISPs
The following photos of David Nolen and Rich Hickey © and courtesy of Mike Bridge. Sources: David, Rich.
- LISP
- unveränderbare Datenstrukturen
- simpel
- dynamisch
- funktional
- pragmatisch
- läuft auf JVM, CLR, JavaScript engines
“Lisp is a programmable programming language.” — John Foderaro
- Ruby:
3 * 4 + 7
- Clojure:
(+ 7 (* 3 4))
- Homoikonisch: Code hat gleiche Struktur wie der Abstract Syntax Tree (AST)
- Ruby ist nicht homoikonisch. Der Interpreter muss den AST aus dem Code erstellen und dabei z.B. die Operratorrangfolge beachten.
(+ 1 1)
- Code ist eine Datenstruktur - eine Clojure Liste
- erstes Listenelement (
+
, Operator) wird ausgeführt, Rest sind Operanden - Macros: Code kann wie jede andere Datenstruktur behandelt und manipuliert werden - z.B.
map
auf Quellcode anwenden.
- wenn der Code eine Datenstruktur ist, warum dann in Textdateien statt in einer Datenbank speichern?
- Chris Granger: Programming inside a Database. Thoughtbot Podcast http://podcasts.thoughtbot.com/giantrobots/111
- An Ex-Microsoft Engineer Raised $2.3 Million To Make Programming Super Simple
- Hashes, Arrays, ... sogar Strings.
x = "MiXeD cAsE"
x.upcase!
=> "MIXED CASE"
x
=> "MIXED CASE" # (same object_id)
- Ruby: meiste Datenstrukturen veränderbar (upcase -vs- upcase!) - verwendete Methoden entscheiden, ob verändert wird
- daneben: Konstanten, object.freeze etc.
- Clojure: Datenstrukturen unveränderbar - es gibt kein upcase! und niemand kann eines in Clojure schreiben. Große Vereinfachung, die auf Sprechebene erfolgen sollte.
- wie arbeitet man dann noch, wenn nichts veränderbar ist? -> Veränderbare Referenzen (in Om: atoms)
- Clojure-Funktionen verändern nie ihre Argumente sondern geben immer veränderte Kopien zurück.
(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)
;; gleicher Befehl mit threading macro (`->`) statt Verschachtelung
(-> my_vec
pop
(conj 11))
=> (11 2 3 4)
;; bleibt von allen Funktionsaufrufen unverändert
;; es kann keine Bang-Funktionen wie in Ruby geben
my_vec
=> (1 2 3 4)
"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".
"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".
- syntax - data
- variables - managed refs
- state, objects - values
- ORM - unadorned data
"Simplicity Matters"
(http://youtu.be/rI8tNMsozo0?t=21m41s)
- hidden encapsulated state (instance variables)
- calling
my_object.some_method(5)
can return different results whensome_method
depends on the object's mutable internal state - Clojure is pragmatic and tries to retain good features of OOP - e.g. multimethods or component: "Managed lifecycle of stateful objects in Clojure"
- opposite of complex (braided, interwoven)
- about one thing
- objective
- opposite of hard
- relative
- easy for me -vs- easy for you
- leichte (easy) Sachen für einfache (simple) halten
gem install hairball
rails new my_blog
geht leicht von der Hand, aber kann einen ganzen Batzen Komplexität mit sich bringen - z.B.devise
...
"Do you know what you ship?"
- in Java geschrieben
- kompiliert Clojure-Code zu Java-Bytecode
- ist in Clojure geschrieben (leider nicht self-hosting!)
- kompiliert ClojureScript-Code zu JavaScript
- ClojureScript hat im Ggs. zu CoffeeScript (weitestgehend JavaScript Semantik) Clojure Semantik
"I totally wrote it off. I was like, “This is not something I’m ever going to use.” But I have a good friend, Brandon Bloom, who was familiar with programming games on the Xbox. When React came out, he was like, “Yeah, it looks weird. But you really should look at how it works because it’s like the way that game developers do game engines.”
Then Pete Hunt went to JSConf in 2013 and he gave a great talk about the design. And I sort of got an epiphany."
http://javascriptjabber.com/107-jsj-clojurescript-om-with-david-nolen
Daten: JSON
Templates: z.B. Handelbars
-
normales JS-MVC:
Daten -> Template -> DOM -
React:
Daten -> Template -> virtueller DOM -> DOM
- 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
often devs still approach performance of JS code as if they are riding a horse cart but the horse had long been replaced with fusion reactor
— Vyacheslav Egorov (@mraleph) December 13, 2013
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
- 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.
- instead of writing JS code that describes changes to the DOM we describe what the DOM should look like.
- "ClojureScript interface to Facebook's React"
- https://github.com/swannodette/om
- globaler App-Zustand
- immutable data structures (Clojure Semantik in CLJS)
- Om Cursor
- undo in 13 Zeilen ClojureScript
- not a memory problem b/c our persistent data structures use structural sharing.
- Probleme mit Globalem App State: Decomposing web app development
- Om benefits from ClojureScript's immutable data structures
- even faster diffing: only reference equality checks -vs- traversing the entire JSON structure.
- wie Go-Blöcke aus Golang - über Macros in Clojure(Script) implementiert
- Make no promises - David Nolen
- Webinar: Designing Front End Applications with core.async
- Communicating sequential processes
- Implementation details of core.async Channels - Rich Hickey
- The Cognicast
- ClojureScript User Group San Francisco
- Rich Hickey. "Simplicity matters". Rails Conf. 2012. http://tinyurl.com/simplicity-matters.
- 4 Features Javascript can steal from Clojure(Script)
- Beating the Averages
- Offizielles Om tutorial
- DataScript
- Chatting cats use DataScript for fun
- Goya pixel editor
- Mein eigenes Solitaire-ähnliches Kartenspiel Omingard
- David Nolen: main ClojureScript maintainer, creator of Om, ex-New York Times, now Cognitect
- Rich Hickey: inventor of Clojure, Cognitect
- Michael Fogus: author of "The Joy of Clojure" and "Functional JavaScript with Underscore.js"
- Carsten Schmidt: coder/media artist (lots of Processing), recently also Clojure(Script) (e.g.: http://devartcodefactory.com/#/objects/edit/box), Clojure tutorial, short portrait, long interview.
- Craig Andera: Cognicast host
- Eric Normand: LISP casts author, Clojure blogger
- Cologne Clojure User Group
photo: Lukas Indruch, source: https://secure.flickr.com/photos/603/5624871391