Skip to content

paulkoegel/alien-technology-9elements

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slides

slides


Preamble

alien brother

"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!"

♫ Attack the Block mixtape


Alien Technology: Ideas from the Clojureverse

9elements Edition


Paul Wittmann
@wakkahari
[email protected]

7. Oktober 2014, Bochum
Railscamp Slides


Technologie wie vom anderen Stern

  • zu gut um wahr zu sein
  • fremdartig

alien technology


Überblick

  • Clojure
    • Warum?
    • Ideen dahinter
    • Wo anfangen?
  • Om
    • unveränderbare Datenstrukturen & globaler Zustand, Undo, core.async
  • Mehr:
    • Overtone, Datomic, DataScript

Meine Motivation

  • 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

Einstieg ins Ökosystem: Vorträge


Einstieg ins Ökosystem: Tools & Infos


Clojure

  • 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.


Rich Hickey


David Nolen


Clojure

  1. LISP
  2. unveränderbare Datenstrukturen
  3. simpel
  4. dynamisch
  5. funktional
  6. pragmatisch
  7. läuft auf JVM, CLR, JavaScript engines

elegant weapons


Code as data / Homoiconicity

“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.

Ausblick: noch weiter gedacht

Chris Granger


Veränderbare Datenstrukturen in Ruby

  • Hashes, Arrays, ... sogar Strings.
x = "MiXeD cAsE"

x.upcase!
=> "MIXED CASE"

x
=> "MIXED CASE" # (same object_id)

Unveränderbare Datenstrukturen]

  • 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.

Beispiel

(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)

linked list


Simplicity

"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 (einfach)

"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 (leicht)

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".


Beispiel

"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".


Complex -vs- Simple

  • syntax - data
  • variables - managed refs
  • state, objects - values
  • ORM - unadorned data

"Simplicity Matters"
(http://youtu.be/rI8tNMsozo0?t=21m41s)


Problem with OOP

  • hidden encapsulated state (instance variables)
  • calling my_object.some_method(5) can return different results when some_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"

state


Zusammengefasst

Simple (einfach)

  • opposite of complex (braided, interwoven)
  • about one thing
  • objective

Easy (leicht)

  • opposite of hard
  • relative
  • easy for me -vs- easy for you

Gefahr gerade für Rubyprogrammierer

  • 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?"

ancestors


Clojure ~= ClojureScript


Clojure compiler

  • in Java geschrieben
  • kompiliert Clojure-Code zu Java-Bytecode

ClojureScript Compiler

  • ist in Clojure geschrieben (leider nicht self-hosting!)
  • kompiliert ClojureScript-Code zu JavaScript
  • ClojureScript hat im Ggs. zu CoffeeScript (weitestgehend JavaScript Semantik) Clojure Semantik

David Nolen über React

"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


Reacts Killer Feature: Virtual DOM

  • DOOM 3 rendering engine

Virtual DOM (VDOM)

Daten: JSON
Templates: z.B. Handelbars

  • normales JS-MVC:
    Daten -> Template -> DOM

  • React:
    Daten -> Template -> virtueller DOM -> DOM


Bottleneck: DOM updates

  • VDOM is a plain JS object
  1. data changes, templates get rerendered
  2. new VDOM gets DIFFed with old one
  3. 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>

Backbone

  • change a user's name that's displayed in several Views on the page: all these views get rerendered entirely

React

  • 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.

Om


Om: Global app state


Om

  • Om benefits from ClojureScript's immutable data structures
  • even faster diffing: only reference equality checks -vs- traversing the entire JSON structure.

Communicating Sequential Processes (CSP) via core.async


Links


Who to follow


Meta-Ex - Music Live Coding with Overtone & Emacs

meta-ex


Zu guter Letzt - wem das alles noch zu wenig ALIEN war

Urbit

photo: Lukas Indruch, source: https://secure.flickr.com/photos/603/5624871391 Alien DJ

About

Alien Technology: Ideas from the Clojureverse - 9elements Edition

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published