Thanks to visit codestin.com
Credit goes to www.slideshare.net

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

Clojurescript slides

  • 2.
  • 3.
  • 4.
    Clojure ... rocks JavaScript ...
  • 5.
    Clojure ... rocks JavaScript ... reaches
  • 6.
  • 7.
    Why ClojureScript? • JavaScriptis 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
  • 8.
    Rationale • Clojure isarguably simpler, more powerful and more robust than JS • JS VMs getting faster • Clojure on JS empowers developers
  • 9.
    Strategy • Compile (asubstantial subset of) Clojure to JS source • Leverage best-of-breed JS approaches • Look beyond the browser
  • 10.
    Non-Objectives • Complete Clojure •Portable large applications • Browser REPL demos etc • The target is production applications
  • 11.
    Tactics • ClojureScript inClojure(Script) • ClojureScript on (Google) Closure
  • 12.
    ClojureScript in Clojure(Script) • Compiler written in Clojure • Macros written in Clojure • Library written in ClojureScript • No JavaScript source files
  • 13.
    CinC • Core abstractionsare protocols • Data structures are deftypes • Excellent mapping to JS under the hood
  • 14.
    REPL • Written inClojure • Hosts embedded Rhino • Compiles to JS on the fly • Rhino evals
  • 15.
    Google Closure • ProductionCode • 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+
  • 16.
    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
  • 17.
    Closure Compiler • OptimizingCompiler • Whitespace only • Within-function • Whole program (advanced mode) • Try it: • http://closure-compiler.appspot.com/home
  • 18.
    Another Minifier, yawn •No! • Closure compiler does symbol replacement • but also expression rewriting, transformation • Dead code elimination • read as: uncalled code elimination
  • 19.
    Why Whole Program OptimizationMatters • 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
  • 20.
    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?
  • 21.
    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
  • 22.
    Whole-program Optimization for theWin • 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
  • 23.
    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
  • 24.
    Find Out More “TheO’Reilly [kloh-zher] book - you know, with the bird on the front”
  • 25.
    What’s There • Compiler •REPL • Primitives • Arity overloading • Macros
  • 26.
    What’s There • Seqs,maps, vectors, sets • and much of supporting library • Symbols, keywords • Destructuring • Regex
  • 27.
    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
  • 28.
    What’s There • 2500+lines of core lib • clojure.string • clojure.set • clojure.walk • clojure.zip
  • 29.
    What’s There • Reader • Why, given JSON? • Sets, keywords, symbols • Metadata • Great fit when Clojure on the server
  • 30.
    What’s There • Namespaces • integrated with Google Closure provide/ require • compile-file, build project, including • deps calculation • invocation of Google Closure compiler
  • 31.
    What’s Not (yet) •Full collection persistence • defrecord • multimethods/hierarchy • Full numerics • Testing • Misc core library
  • 32.
    What Won’t Be •Thread-related things • eval and runtime compilation • structs, proxy, Java type-stuff • Runtime reification of • Vars, namespaces, protocols etc
  • 33.
    It’s Alpha! • Bugs •Missing bits • Rough edges • Work to do
  • 34.
    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
  • 35.
    Participating • This isa Clojure/dev project • all with Clojure CAs welcome to participate • Plenty to do • Libraries • Environment • Tooling
  • 36.
    Face Time • TheConj! • Nov. 10-12 Raleigh, NC • With training: Nov. 7 -12 • http://clojure-conj.org/ • Early registration ends soon • Core Fridays
  • 37.
  • 38.
    Summary • ClojureScript is • Clojure's client story • Clojure's mobile story • Clojure's CLI scripting story • The power of Clojure • The reach of JavaScript