clojurescript slides

38

Upload: elliando-dias

Post on 06-May-2015

4.041 views

Category:

Technology


2 download

DESCRIPTION

clojurescript

TRANSCRIPT

Page 1: Clojurescript slides
Page 2: Clojurescript slides

Clojure ...

Page 3: Clojurescript slides

Clojure ...

rocks

Page 4: Clojurescript slides

Clojure ...

rocks

JavaScript ...

Page 5: Clojurescript slides

Clojure ...

rocks

JavaScript ...

reaches

Page 6: Clojurescript slides

ClojureScript

Page 7: Clojurescript slides

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

Page 8: Clojurescript slides

Rationale

• Clojure is arguably simpler, more powerful and more robust than JS

• JS VMs getting faster

• Clojure on JS empowers developers

Page 9: Clojurescript slides

Strategy

• Compile (a substantial subset of) Clojure to JS source

• Leverage best-of-breed JS approaches

• Look beyond the browser

Page 10: Clojurescript slides

Non-Objectives

• Complete Clojure

• Portable large applications

• Browser REPL demos etc

• The target is production applications

Page 11: Clojurescript slides

Tactics

• ClojureScript in Clojure(Script)

• ClojureScript on (Google) Closure

Page 12: Clojurescript slides

ClojureScript in Clojure(Script)

• Compiler written in Clojure

• Macros written in Clojure

• Library written in ClojureScript

• No JavaScript source files

Page 13: Clojurescript slides

CinC

• Core abstractions are protocols

• Data structures are deftypes

• Excellent mapping to JS under the hood

Page 14: Clojurescript slides

REPL

• Written in Clojure

• Hosts embedded Rhino

• Compiles to JS on the fly

• Rhino evals

Page 15: Clojurescript slides

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+

Page 16: Clojurescript slides

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

Page 17: Clojurescript slides

Closure Compiler

• Optimizing Compiler

• Whitespace only

• Within-function

• Whole program (advanced mode)

• Try it:

• http://closure-compiler.appspot.com/home

Page 18: Clojurescript slides

Another Minifier, yawn

• No!

• Closure compiler does symbol replacement

• but also expression rewriting, transformation

• Dead code elimination

• read as: uncalled code elimination

Page 19: Clojurescript slides

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

Page 20: Clojurescript slides

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?

Page 21: Clojurescript slides

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

Page 22: Clojurescript slides

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

Page 23: Clojurescript slides

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

Page 24: Clojurescript slides

Find Out More

“The O’Reilly [kloh-zher] book - you know, with the bird on the

front”

Page 25: Clojurescript slides

What’s There

• Compiler

• REPL

• Primitives

• Arity overloading

• Macros

Page 26: Clojurescript slides

What’s There

• Seqs, maps, vectors, sets

• and much of supporting library

• Symbols, keywords

• Destructuring

• Regex

Page 27: Clojurescript slides

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

Page 28: Clojurescript slides

What’s There

• 2500+ lines of core lib

• clojure.string

• clojure.set

• clojure.walk

• clojure.zip

Page 29: Clojurescript slides

What’s There

• Reader

• Why, given JSON?

• Sets, keywords, symbols

• Metadata

• Great fit when Clojure on the server

Page 30: Clojurescript slides

What’s There

• Namespaces

• integrated with Google Closure provide/require

• compile-file, build project, including

• deps calculation

• invocation of Google Closure compiler

Page 31: Clojurescript slides

What’s Not (yet)

• Full collection persistence

• defrecord

• multimethods/hierarchy

• Full numerics

• Testing

• Misc core library

Page 32: Clojurescript slides

What Won’t Be

• Thread-related things

• eval and runtime compilation

• structs, proxy, Java type-stuff

• Runtime reification of

• Vars, namespaces, protocols etc

Page 33: Clojurescript slides

It’s Alpha!

• Bugs

• Missing bits

• Rough edges

• Work to do

Page 34: Clojurescript slides

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

Page 35: Clojurescript slides

Participating

• This is a Clojure/dev project

• all with Clojure CAs welcome to participate

• Plenty to do

• Libraries

• Environment

• Tooling

Page 36: Clojurescript slides

Face Time

• The Conj!

• Nov. 10-12 Raleigh, NC

• With training: Nov. 7 -12

• http://clojure-conj.org/

• Early registration ends soon

• Core Fridays

Page 37: Clojurescript slides

Demo

• REPL

• Compilation

• Web app

• CLI app

Page 38: Clojurescript slides

Summary

• ClojureScript is

• Clojure's client story

• Clojure's mobile story

• Clojure's CLI scripting story

• The power of Clojure

• The reach of JavaScript