Download - Clojurescript slides
Clojure ...
Clojure ...
rocks
Clojure ...
rocks
JavaScript ...
Clojure ...
rocks
JavaScript ...
reaches
ClojureScript
Why ClojureScript?
• JavaScript is the only programming technology in key environments
• e.g. the browser
• has the greatest reach in mobile
• but is not very robust
• While demand for sophisticated applications increases
Rationale
• Clojure is arguably simpler, more powerful and more robust than JS
• JS VMs getting faster
• Clojure on JS empowers developers
Strategy
• Compile (a substantial subset of) Clojure to JS source
• Leverage best-of-breed JS approaches
• Look beyond the browser
Non-Objectives
• Complete Clojure
• Portable large applications
• Browser REPL demos etc
• The target is production applications
Tactics
• ClojureScript in Clojure(Script)
• ClojureScript on (Google) Closure
ClojureScript in Clojure(Script)
• Compiler written in Clojure
• Macros written in Clojure
• Library written in ClojureScript
• No JavaScript source files
CinC
• Core abstractions are protocols
• Data structures are deftypes
• Excellent mapping to JS under the hood
REPL
• Written in Clojure
• Hosts embedded Rhino
• Compiles to JS on the fly
• Rhino evals
Google Closure
• Production Code
• Closure Compiler
• virtually all of Google’s JS goes through this
• Closure Library
• Used by Google Gmail, Maps, Docs, Sites, Books, Reader, Calendar, Photos, Google+
Why Give Google Closure Away?
• Be cool
• Make friends
• See if it sticks
• Not using it anymore
• Sucker community into maintaining
• They want the web to win as an application platform
Closure Compiler
• Optimizing Compiler
• Whitespace only
• Within-function
• Whole program (advanced mode)
• Try it:
• http://closure-compiler.appspot.com/home
Another Minifier, yawn
• No!
• Closure compiler does symbol replacement
• but also expression rewriting, transformation
• Dead code elimination
• read as: uncalled code elimination
Why Whole Program Optimization Matters• Libraries
• Large libraries
• Many libraries
• Sum of many minified libs is large again
• What % of each lib do you use in one app?
• Diminishing returns from delayed loading and modularity efforts
Making it work• Convention, and lots of it
• Welcome to Javascript!
• Trickiness abounds - string access to properties, exporting, side-effects
• Google’s conventions not widely followed
• What if we had a Javascript-emitting language that always emitted advanced-mode compatible code?
Closure Library• Huge!
• UI, events, DOM, communications, testing, algorithms and data structures...
• Packaging and dependency resolution
• Yet, not
• Symbiotic with Closure compiler
• Your app will include only the code it uses
• require lib != use all of it
Whole-program Optimization for the Win
• Google has decided this is the key to delivering
• rich applications
• over thin wires
• to memory constrained devices
• Given away sophisticated tools for making that work
ClojureScript on (Google) Closure
• Emits advanced-mode compatible code
• encapsulates conventions
• Participates in dependency system
• maps Clojure namespaces to Google’s optimizable format
• Profit! - whole-program optimization and large library support
Find Out More
“The O’Reilly [kloh-zher] book - you know, with the bird on the
front”
What’s There
• Compiler
• REPL
• Primitives
• Arity overloading
• Macros
What’s There
• Seqs, maps, vectors, sets
• and much of supporting library
• Symbols, keywords
• Destructuring
• Regex
What’s There• deftypes
• core datatypes
• protocols
• all abstractions
• extend-type, extend-protocol
• can extend primitives e.g. string, nil, default
• Both defined in terms of primitives
What’s There
• 2500+ lines of core lib
• clojure.string
• clojure.set
• clojure.walk
• clojure.zip
What’s There
• Reader
• Why, given JSON?
• Sets, keywords, symbols
• Metadata
• Great fit when Clojure on the server
What’s There
• Namespaces
• integrated with Google Closure provide/require
• compile-file, build project, including
• deps calculation
• invocation of Google Closure compiler
What’s Not (yet)
• Full collection persistence
• defrecord
• multimethods/hierarchy
• Full numerics
• Testing
• Misc core library
What Won’t Be
• Thread-related things
• eval and runtime compilation
• structs, proxy, Java type-stuff
• Runtime reification of
• Vars, namespaces, protocols etc
It’s Alpha!
• Bugs
• Missing bits
• Rough edges
• Work to do
Who Did This?• Clojure/core and friends:
Aaron Bedra, Alan Dipert, Alex Redington
Bobby Calderwood, Brenton Ashworth
Chris Houser, Devin Walters, Eric Thorsen
Frank Failla, Michael Fogus, Jess Martin
Luke VanderHart, Chris Redinger, Jonathan Claggett
Stuart Halloway, Stuart Sierra, Tom Hickey
Participating
• This is a Clojure/dev project
• all with Clojure CAs welcome to participate
• Plenty to do
• Libraries
• Environment
• Tooling
Face Time
• The Conj!
• Nov. 10-12 Raleigh, NC
• With training: Nov. 7 -12
• http://clojure-conj.org/
• Early registration ends soon
• Core Fridays
Demo
• REPL
• Compilation
• Web app
• CLI app
Summary
• ClojureScript is
• Clojure's client story
• Clojure's mobile story
• Clojure's CLI scripting story
• The power of Clojure
• The reach of JavaScript