Clojure/West 2013 Conference Highlights Clojure/West 2013
Table of Contents
- Overview
- Schedule
- Sunday: ClojureScript: Up and Running
- Sunday Evening: Ground Kontrol Pre-party
- Monday
- Welcome, Alex Miller theater
- Cascalog: Logic programming over Hadoop, Alex Robbins studio
- RESTful Clojure, Siva Jagadeesan studio
- Engines of Abstraction, Jim Duey theater
- Clojure in the Large, Stuart Sierra theater
- Pedestal: Architecture and Services, Brenton Ashworth, Tim Ewald theater clojurescript
- Pedestal: Rich Client Applications, Brenton Ashworth, Tim Ewald theater
- Beyond Contracts: An exploration into unified specifications, Paul deGrandis theater
- Design, Composition, and Performance, Rich Hickey theater
- Monads, Unsession seq1
- Profiling Clojure, Unsession seq1
- Functional Reactive Programming, Unsession seq1
- TODO Key Signing, Unsession seq1
- Tuesday
- Winning the War on Javascript, Bodil Stokke theater clourescript
- Metaprogramming Polyfill: Feed Clojure Data to your JavaScript Libraries, Tom White theater
- Securing Clojure webapps and services with Friend, Chas Emerick theater
- clj-v8 and the Dieter Asset Pipeline, Paul Biggar studio
- FRP in ClojureScript with Flapjax, Alan Dipert theater clojurescript
- Introducing ClojureScript-in-ClojureScript, Joel Martin theater clojurescript
- Tuesday Evening: miniKanren Confo
- Wednesday
- Editing Clojure Effectively with Emacs, Ryan Neufeld studio emacs
- Ritz - the missing Clojure tooling, Hugo Duncan studio emacs
- A shorter path from Clojure to Clojurescript, Roman Gonzalez studio
- Lightning talks
- Simulation Testing with Simulant, Stuart Halloway theater
- Racket: Metaprogramming Time!, Matthew Flatt theater
Schedule
Sunday: ClojureScript: Up and Running
http://clojurescript.eventbrite.com
- Using the Leiningen build tool
- Understanding the ClojureScript compiler
- JavaScript interop and libraries
- Working with the Google Closure Compiler
- Using the Google Closure Libraries
- Manipulating HTML in a browser
- Building event-driven applications
- Communicating with a Clojure server
- collectiveworkspace
Slides
Discussion
- Don't use the GClosure UI widgets since the OO style is a poor fit
- Contrast with The Good Parts: human readability vs. optimization
- cljx allows switching based on Clojure or Clojurescript environment
Compilations
- Always run with warnings
{ :warnings :true }
- No sourcemap support at present but currently in progress
- Development vs. production just change the meanings for :output-to and :output-dir
- In production :output-to is full application and :output-dir is just an intermediate location
- Always include :optimizations
- Include clojurescript dependency for access in repl
src/cljs resources/public/javascript
- $ lein cljsbuild auto
- Development HMTL: GClosure bootstrap, application, main namespace, function
- Must be separate <script> calls
- Production is just :output-to then call function
bREPL
- Create the 3000 brepl.html test page
- Create the 9000 endpoint
- lein run
- lein trampoline cljsbuild repl-listen
(js/alert 1) (set! (.-title js/document) "New Page Title")
Differences and Interoperability
- cljs.reader
- https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure
- Namespace: ns is built into the compiler and is only a subset of the Clojure ns
- Concurrency primitives aren't available since JS is single-threaded: no refs, agents or futures
- Doesn't change the Clojure single state: application state is stored in atoms, "State, Identity, and Value" http://clojure.org/state
- Macros: :require-macros must be in the Clojure: define the macro in src/clj rather than src/cljs
- Core algorithmic runtime characteristics for for data structures will be the same but there are constant changes that allow for improvements for the JavaScript run-time
- js/ is the global JavaScript execution context
- Examples won't work in IE for things like js/alert: alert() isn't a function in IE so a reference can't be found with call(window, alert)
- When using JavaScript libraries that use "this" you need to call with (.my-method js/MyNamespace "my argument") otherwise use the idiomatic form of (MyNamespace/my-method "my argument")
- A dot appended to the name of a function call it will be invoked with "new"
Labs
Flocking simulation.
Namespaces and Dependencies
<body> <script src="build/deps.js"></script> <script>goog.require('boids.main');</script> <script type="text/javascript" src="file://localhost/Users/jwalsh/sandbox/boids/resources/public/build/goog/string/stringbuffer.js"></script> <script type="text/javascript" src="file://localhost/Users/jwalsh/sandbox/boids/resources/public/build/goog/../cljs/core.js"></script> <script type="text/javascript" src="file://localhost/Users/jwalsh/sandbox/boids/resources/public/build/goog/../boids/euclidean-vector.js"></script> <script>boids.main.main()</script> <canvas width="1383" height="831"></canvas> </ body>
Manipulating Advanced
window.addEventListener( 'mousemove', function(e) { for (var p in boids.main.default_options.strobj) { if(p.indexOf('goal') !== -1 && p.indexOf('goal-') === -1) { boids.main.default_options.strobj[p].tail = [e.x, e.y]; } } console.log(e.x) }, false)
Notes
- Look at Clojurescript with Angular
- Event SeattleJS noted difficultly with Ember
- JS tooling system not well known (e.g., optimization options)
Sunday Evening: Ground Kontrol Pre-party
If you'll be in Portland Sunday night, stop by the legendary Ground Kontrol arcade (511 Northwest Couch Street, 97209), just a couple blocks from the conference hotel. We'll have the whole place reserved from 7-9 pm with FREE PLAY on all games and pinball machines! Two Sigma stepped up to sponsor the party so there will also be an open bar! Huge thanks to Two Sigma. Early registration will also be available.
Monday
Welcome, Alex Miller theater
Cascalog: Logic programming over Hadoop, Alex Robbins studio
RESTful Clojure, Siva Jagadeesan studio
Goals
Look at order cancellation process that would be:
- Scalablable
- Maintainable
- Recoverable
- Loosely coupled
- Secure
Allow for version and status that could be provided by a client.
- Spread complexity
- Reduce complexity
- Make complexity learnable
- Definition driven with emphasis on Fielding rather than practice
- Look at Richardson's macurity model.
- Seems to care about "what is RESTful"
v1 (actions parameter)
- Set up the Compjure routes
- Single end-ping
- No caching
- Has side-effects
Use parameters as
v2 (URI)
General Rails approach.
/GET
v3 (uniform interface)
General overview of HTTP status codes.
/POST /GET /GET/1 /DELETE
Application state transition logic is encoded in the clinet
v4 (hypermedia/hypertext awareness)
Now includes the links as part of the payload (resource states).
Questionable if this is valuable in practice during initial product definition unless the end-points are only internal…do the names mean the same things over time (even with versioning).
The question is how much cost there is for client libraries but the hypermedia links are more stable but one migrates the cost from the change in the server end-point (i.e., the URI) rather than the name of the media links.
Is the caching definition a valid contract with the client?
Version
- URI
- Media type considered better
Tasks
Attempts to have a level/design based analysis of end-points.
Look at Netflix API which was considered the only RESTful API.
Engines of Abstraction, Jim Duey theater
Topics
- monads
- composition
- applicative functors
- comonads
Clojure in the Large, Stuart Sierra theater
Design
- http://www.laputan.org/mud/
- http://www.codinghorror.com/blog/2007/11/the-big-ball-of-mud-and-other-architectural-disasters.html
@INPROCEEDINGS{Foote97bigball, author = {Brian Foote and Joseph Yoder}, title = {Big Ball of Mud}, booktitle = {Pattern Languages of Program Design}, year = {1997}, pages = {653--692}, publisher = {Addison-Wesley} }
Globals, State, Constructors
;; Problem (def state-1 (ref {})) ;; Hiding (let [state-1 (ref {})]) ;; Use constructors (defn constructor [] {: (ref {})})
System
(defrecord System)
Pedestal: Architecture and Services, Brenton Ashworth, Tim Ewald theater clojurescript
Ring restructuring
Clojure, ClojureScript and EDN
Server-sent events (SSE)
Apps and Views
Messages include topic and type, param.
Pedestal: Rich Client Applications, Brenton Ashworth, Tim Ewald theater
Running
lein new pedestal-service my-service lein new pedestal-app my-app
Beyond Contracts: An exploration into unified specifications, Paul deGrandis theater
Design, Composition, and Performance, Rich Hickey theater
Monads, Unsession seq1
Began by looking at the type of atoms that can be wrapped in Clojure.
Sequences
- define bind (flatten)
;; Sequence monadic function (defn bind [mv mf] (apply concat (map mf mv)))
- sequence monads
- result map and flatten
For other cases what we see are
(defn f [x] (hash-set (* 5 x) (* 2 x))) (defn g [x] (hash-set (+ 5 x) (+ 2 x))) (f 3) (g 3) (defn bind [mv mf] (apply clojure.set/union (map mf mv)))
This bind and hash-set obey the monadic laws.
Functions
This requires flattening of a function: takes a value and returns a fn.
(*1) ;; executes (defn bind [mv mf] (let [x (mv) new-mv (mf x)] (fn [] (new-mv)))) (defn f [x] (constantly (* 5 x))) (bind (constantly 5) f) (*1)
Without mf taking a parameter this is largely useless.
State Monad
Allows global mutable state with pure functions.
(defn result [x] (fn [state] [x state])) (result 1) (*1 :ok)
Gives you a way (e.g., in Haskell) the flow through the application giving global mutable state.
Profiling Clojure, Unsession seq1
- VisualVM
(defn baz [n] (-> n (.replaceAll "2" "3") (.replaceAll "4" "5") ))
Functional Reactive Programming, Unsession seq1
TODO Key Signing, Unsession seq1
KEY=0390c045
ff62 b2cd cdd6… scott francis
http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0xB3DB9C50D475C1D9
Tuesday
Winning the War on Javascript, Bodil Stokke theater clourescript
- Need klass system in Clojurescript
- Promises as implemented in Clojurescript
- Red Lobster and Dog Fort
- Promises: p/realize p/on-realised; chained promises
(p/realise p p*)
- Examples of Promises now includes mongo/connect
- http://www.pauldee.org/blog/2012/clojurescript-and-node-js-an-experience-report/
- https://github.com/bodil/redlobster
Metaprogramming Polyfill: Feed Clojure Data to your JavaScript Libraries, Tom White theater
- Cover d3 programming
- Seems like a reason
- (vec "abcdef") becomes array
- edn style: enter update exit
- https://github.com/dribnet/strokes
- https://github.com/teropa/hiccups
- Completed additional work against Leaflet and Angular
- Angular seems to be the clear winner against Ember based on SeattleJS and Clojure/West
Securing Clojure webapps and services with Friend, Chas Emerick theater
- Authentication
- Authorization
clj-v8 and the Dieter Asset Pipeline, Paul Biggar studio
This was discussed as part of Clojure/West 2012.
- back-end in Clojure; front-end in Rails
- migrated to single page JavaScript application
- http://www.youtube.com/watch?v=LxQ6olQjebg
- https://github.com/edgecase/dieter
FRP in ClojureScript with Flapjax, Alan Dipert theater clojurescript
- http://www.flapjax-lang.org/tutorial/
- Behaviors
- Traits
- Events
- Arrows
- Streams
- Cell
See associated links for FRP: https://pinboard.in/u:jwalsh/t:frp
Introducing ClojureScript-in-ClojureScript, Joel Martin theater clojurescript
- cljs debugger on page
- text/clojurescript
- namespaced cljs interop
- externally referenced script src
Tuesday Evening: miniKanren Confo
Logic programming in the wild, Gabriel Pickard
Intro to CLP with core.logic, Ryan Senior
Molog: Typed Functional Logic Programming in Haskell, Adam Foltzer
The Architecture of core.logic, David Nolen
core.logic.nominal, Nada Amin
The Unreasonable Schemers, Dan Friedman and William Byrd
Wednesday
Editing Clojure Effectively with Emacs, Ryan Neufeld studio emacs
REPL and paredit
Starter Kit + additional options
- http://bit.ly/clj-ready
- C-c M-n - switch namespace
NREPL
- M-.
Reinstall peepopen
Ritz - the missing Clojure tooling, Hugo Duncan studio emacs
nrepl-ritz-jack-in
exception filters
Enable via the configuration:
(setq nrepl-popup-stacktraces-in-repl t)
- adding filter from the stack trace
- edit
- disable
- expand a specific frame
- view source for a frame with "v"
nrepl-ritz-threads
A shorter path from Clojure to Clojurescript, Roman Gonzalez studio
Translating Clojure to Clojurescript
- -invoke vs. invoke
- :require vs. :require-macro
DALAP
https://github.com/BirdseyeSoftware/lein-dalap
- cljx
- valid clojure as input and clojurescript as out
- selectors and transformers of the clojure data structures (ala CSS)
Create a dalaprules.clj file with the selectors:
- don't include some forms in the Clojurescript out
There are some default rule s for
- java.lang.String and String
- defref and -deref
But this doesn't cover any differences in the semantics between Java and JavaScript.
Testing
Clojurescript testing was the normal list:
- jasmine
- qunit
- buster-cljs
Wrapper of clojure.test: