ClojureScript
  Anatomy
Targeting JavaScript
Why?
Targeting JavaScript
Primacy
                              of
                          Semantics
I also regard syntactical problems as essentially irrelevant to programming languages at
  their present stage ... the urgent task in programming languages is to explore the field
                                                                  of semantic possibilities.
     — Christopher Strachey - “Fundamental Concepts in Programming Languages”
JavaScript has much in common with
                              Scheme.

                     It is a dynamic language.

             It has a flexible datatype (arrays) that can
                   easily simulate s-expressions.

               And most importantly, functions are
                           lambdas.




http://javascript.crockford.com/little.html
Power Points
• Reach
 • browser, shell, mobile, databases
• First-class functions
• Prototypal inheritance
• Closures
• Literal syntax
Pain Points
Pain Points


• Everything else
JavaScript
JavaScript
    • Safety through convention
JavaScript
    • Safety through convention
    • Rampant mutation
JavaScript
    • Safety through convention
    • Rampant mutation
    • Globals
JavaScript
    • Safety through convention
    • Rampant mutation
    • Globals
    • this
JavaScript
    • Safety through convention
    • Rampant mutation
    • Globals
    • this
    • Truthiness
JavaScript
    • Safety through convention
    • Rampant mutation
    • Globals
    • this
    • Truthiness
    • Objects make poor modules
JavaScript
•   Safety through convention


•   Rampant mutation


•   Globals


•   this


•   Truthiness


•   Objects make poor modules
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation


•   Globals


•   this


•   Truthiness


•   Objects make poor modules
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation
                                • Low Compression
                                 Potential
•   Globals


•   this


•   Truthiness


•   Objects make poor modules
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation
                                • Low Compression
                                 Potential
•   Globals
                                • Limited data formats
•   this


•   Truthiness


•   Objects make poor modules
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation
                                • Low Compression
                                 Potential
•   Globals
                                • Limited data formats
•   this
                                • Limited abstractions
•   Truthiness


•   Objects make poor modules
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation
                                • Low Compression
                                 Potential
•   Globals
                                • Limited data formats
•   this
                                • Limited abstractions
•   Truthiness
                                • ==
•   Objects make poor modules
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation
                                • Low Compression
                                 Potential
•   Globals
                                • Limited data formats
•   this
                                • Limited abstractions
•   Truthiness
                                • ==
•   Objects make poor modules
                                • Optional semicolons
JavaScript
•   Safety through convention
                                • Callbacks
•   Rampant mutation
                                • Low Compression
                                 Potential
•   Globals
                                • Limited data formats
•   this
                                • Limited abstractions
•   Truthiness
                                • ==
•   Objects make poor modules
                                • Optional semicolons
                                • Missing `new`
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 function init(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 function init(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 function init(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 function init(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 var init = function(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 var init = function(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 var init = function(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
my = my || {};
my.awesome = my.awesome || {};
my.awesome.lib = my.awesome.lib ||
{};

my.awesome.lib = (function(){
 var that = {};

 var init = function(){
    /* do something */
 };

 that.foo = true;
 that.init = init;

  return that;
}());

my.awesome.lib.frob = (function($){
 function privateFun(){
   /* do something */
 }

 return function() {
    /* do something with $ */
 };
Google Closure

• Standard library
• Dependency system
• Compiler/minifier (GClosure)
• Templating language
• 1 kajillion man-hours of effort
Google Closure

• Standard library
• Dependency system
• Compiler/minifier (GClosure)
• Templating language
• 1 beellion man-hours of effort
convention




    convention


  convention

 convention
convention
Primacy
                      of
                    Syntax
     one could say that all semantics is being represented as syntax
... semantics has vanished entirely to be replaced with pure syntax.
                                    — John Shutt - “Primacy of Syntax”
CoffeeScript
the web be
Namespaces
ECMAScript.Next
JSModule

                             nodules


       modules.js            curl.js
Namespaces


fogus.my.lib.frobnicate();
Namespaces
fogus = fogus || {};

fogus.my = fogus.my || {};

fogus.my.lib = fogus.my.lib || {};
Namespaces
(ns fogus.my.lib)

(defn frobnicate [] :frobbed!)

    goog.provide(‘fogus.my.lib)
    ;

    fogus.my.lib = function() {
       return “□ :frobbed!”
    };
Compression
 Potential
Take your pick
(ns fogus.my.lib)


goog.provide(‘fogus.my.lib’);


fogus = fogus || {};

fogus.my = fogus.my || {};

fogus.my.lib = fogus.my.lib || {};
Take your pick
(ns fogus.my.lib)


goog.provide(‘fogus.my.lib’);


fogus = fogus || {};

fogus.my = fogus.my || {};

fogus.my.lib = fogus.my.lib || {};
Abstracti ns
Abstractions
• Protocols at the bottom
 • ISeq, IMap, ILookup, IDeref, etc.
• Realizing powerful immutable types
 • Map, List, Vector, etc.
• Extended to JavaScript
 • strings, null, arrays, etc.
JavaScript
    the
   Parts
Functional Inheritance
       Pattern

• Private data
• Access to super methods
• Missing new safe
Functional Inheritance
                    Pattern
var person = function(spec) {
  var that = {};

     that.getName = function() {                  var me = person({'name' : 'Fogus'});
        return spec.name;                         me.getName()
     };                                           //=> 'Fogus'
     return that;
};

var man = function(spec) {
  var that = person(spec);
  var super_getName = that.superior('getName');
                                                  var me = man({'name' : 'Fogus'});
     that.getName = function() {                  me.getName()
        return "Mr. " + super_getName();          //=> 'Mr. Fogus'
     };
     return that;
};
Functional Inheritance
  Pattern Dangers
• Harder to minify
• Larger memory footprint
• Cannot update instances
• Eliminates instanceof
• Mucks with Function.prototype and
  Object.prototype in an unsafe way
Pseudo-classical
               Inheritance Pattern
Person = function(name) {
   this._name = name;
};
                                             var me = new Person('Fogus');
Person.prototype.getName = function() {      me.getName()
   return this._name;                        //=> 'Fogus'
};


Man = function(name) {
   Person.call(this, name);
};

inherits(Man, Person);                       var me = new Man('Fogus');
                                             me.getName()
Man.prototype.getName = function() {         //=> 'Mr. Fogus'
   return "Mr. "
          + Man._super.getName.call(this);
};
Pseudo-classical
   Inheritance Pattern
• Harder Easier to minify
• Larger Smaller memory footprint
• Cannot Can update instances
• Eliminates instanceof
• Mucks with Clean
  Function.prototype and
  Object.prototype
Safe Extension


String.prototype.cljs$core$first = ...

Object.prototype.my$lib$first = ...
me._name
//=> ‘Fogus’
Minification


• Inlining
• Renaming
• Dead-code elimination
Inlining
Functional Inheritance
               Inlining
var person = function(spec) {      var myName = me.getName();
  var that = {};                   var sig = signature({‘name’ : myName});
                                   sig.toString();
     that.getName = function() {   //=> ‘Sent from teh Fogus iPhone’
        return spec.name;
     };
     return that;
};
Functional Inheritance
               Inlining
var person = function(spec) {          var myName = me.getName();
  var that = {};                       var sig = signature({‘name’ : myName});
                                       sig.toString();
     that.getName = function() {       //=> ‘Sent from teh Fogus iPhone’
        return spec.name;
     };
     return that;
};




                                   ?
Functional Inheritance
               Inlining
var person = function(spec) {              var myName = me.getName();
  var that = {};                           var sig = signature({‘name’ : myName});
                                           sig.toString();
     that.getName = function() {           //=> ‘Sent from teh Fogus iPhone’
        return spec.name;
     };
     return that;
};




                    var sig = signature({‘name’ : me.getName()});
                    sig.toString();
                    //=> ‘Sent from teh Fogus iPhone’
Inlining
Pseudo-classical Inlining
Person = function(name) {
   this._name = name;
                                              var myName = me.getName();
};
                                              var sig = new Signature(myName);
                                              sig.toString();
Person.prototype.getName = function() {
                                              //=> ‘Sent from teh Fogus iPhone’
   return this._name;
};




                                          ?
Pseudo-classical Inlining
Person = function(name) {
   this._name = name;
                                            var myName = me.getName();
};
                                            var sig = new Signature(myName);
                                            sig.toString();
Person.prototype.getName = function() {
                                            //=> ‘Sent from teh Fogus iPhone’
   return this._name;
};




                       var sig = new Signature(me._name);
                       sig.toString();
                       //=> ‘Sent from teh Fogus iPhone’
Renaming
Functional Inheritance
      Renaming
   var person = function(spec) {
     var that = {};

        that.getName = function() {
           return spec.name;
        };
        return that;
   };

   var man = function(spec) {
     var that = person(spec);
     var super_getName = that.superior(‘getName’);

        that.getName = function() {
           return "Mr. " + super_getName();
        };
        return that;
   };
Functional Inheritance
      Renaming
   var person = function(spec) {
     var that = {};

        that.getName = function() {
           return spec.name;
        };
        return that;
   };

   var man = function(spec) {
     var that = person(spec);
     var super_getName = that.superior(‘getName’);

        that.getName = function() {
           return "Mr. " + super_getName();
        };
        return that;
   };
Renaming
Pseudo-classical
   Renaming
Person = function(name) {
   this._name = name;
};

Person.prototype.getName = function() {
   return this._name;
};


Man = function(name) {
   Person.call(this, name);
};

inherits(Man, Person);

Man.prototype.getName = function() {
   return "Mr. "
          + Man._super.getName.call(this);
};
Pseudo-classical
   Renaming
Person = function(name) {
   this._name = name;
};

Person.prototype.o = function() {
   return this._name;
};


Man = function(name) {
   Person.call(this, name);
};

inherits(Man, Person);

Man.prototype.getName = function() {
   return "Mr. "
          + Man._super.o.call(this);
};
Dead Code
Dead-code Elimination
       Intro
(let [a 1
      b 2
      a b]
  a)

;=> 2
Dead-code Elimination
       Intro
               (function (){
(let [a 1        var a__847 = 1;
      b 2        var b__848 = 2;
      a b]       var a__849 = b__848;
  a)
                 return a__849;
;=> 2          })();
Dead-code Elimination
       Intro
                 (function (){
(let [a 1          var a__847 = 1;
      b 2          var b__848 = 2;
      a b]         var a__849 = b__848;
  a)
                   return a__849;
;=> 2            })();




             ?
Dead-code Elimination
       Intro
                 (function (){
(let [a 1          var a__847 = 1;
      b 2          var b__848 = 2;
      a b]         var a__849 = b__848;
  a)
                   return a__849;
;=> 2            })();




             2
Dead-code Elimination
       Intro
               (function (){
(let [a 1        var a__847 = 1;
      b 2        var b__848 = 2;
      a b]       var a__849 = b__848;
  a)
                 return a__849;
;=> 2          })();
Functional Inheritance
     Dead-code
   var person = function(spec) {
     var that = {};
     var hasBeard = false;

        that.getName = function() {
           return spec.name;
        };
        return that;
   };

   var man = function(spec) {
     var that = person(spec);
     var super_getName = that.superior(‘getName’);

        that.getName = function() {
           return "Mr. " + super_getName();
        };
        return that;
   };
Functional Inheritance
     Dead-code
   var person = function(spec) {
     var that = {};
     var hasBeard = false;

        that.getName = function() {
           return spec.name;
        };
        return that;
   };

   var man = function(spec) {
     var that = person(spec);
                                                     All good
     var super_getName = that.superior(‘getName’);
                                                      Right?
        that.getName = function() {
           return "Mr. " + super_getName();
        };
        return that;
   };
Functional Inheritance
     Dead-code
   var person = function(spec) {
     var that = {};
     var hasBeard = false;

        that.getName = function() {            Cursed
           return spec.name;
        };
        return that;
                                              Closures!
   };

   var man = function(spec) {
     var that = person(spec);
     var super_getName = that.superior(‘getName’);

        that.getName = function() {
           return "Mr. " + super_getName();
        };
        return that;
   };
Dead Code
Pseudo-classical
  Dead-code
Person = function(name) {
   this._name = name;
   this._hasBeard = false;
};

Person.prototype.getName = function() {
   return this._name;
};


Man = function(name) {
   Person.call(this, name);
};

inherits(Man, Person);

Man.prototype.getName = function() {
   return "Mr. "
          + Man._super.getName.call(this);
};
Pseudo-classical
  Dead-code
Person = function(name) {
   this._name = name;
   this._hasBeard = false;
};

Person.prototype.getName = function() {
   return this._name;
};


Man = function(name) {
   Person.call(this, name);
};

inherits(Man, Person);

Man.prototype.getName = function() {
   return "Mr. "
          + Man._super.getName.call(this);
};
Pseudo-classical
  Dead-code
Person = function(name) {
  this._name = name;

};
                              kthxbai
Person.prototype.getName = function() {
   return this._name;
};


Man = function(name) {
   Person.call(this, name);
};

inherits(Man, Person);

Man.prototype.getName = function() {
   return "Mr. "
          + Man._super.getName.call(this);
};
There’s more
 to life than
     this
Memory Footprint

• Crockford
 • Closure per-method, per-type
 • Leaky (holds a reference to all variables)
• Pseudo-classical
 • No closures needed
Live
Instance Updating


• Problem
 • How to update every instance in the
    system with new behavior?
Functional Inheritance
       Updating
         var person = function(spec) {
           var that = {};

              that.getName = function() {
                 return spec.name;
              };
              return that;
         };

         var me = person({'name' : 'Fogus'});
         var you = person({'name' : 'Cersei'});



How can we add hasBeard to every instance
           now and in the future?
Functional Inheritance
       Updating
         var person = function(spec) {
           var that = {};

              that.getName = function() {
                 return spec.name;
              };
              return that;
         };

         var me = person({'name' : 'Fogus'});
         var you = person({'name' : 'Cersei'});



How can we add hasBeard to every instance
           now and in the future?
  One at a time... every single time
ClojureScript
   Cares.
ClojureScript
            Extending
                 (defprotocol Catable
                   (cat [this other]))

                 (def sound1 "Meow")
                 (def sound2 "Mao")

                 (cat sound1 sound2)
                 ; ASPLODE!




How can we allow cat to work with every instance
              now and in the future?
ClojureScript
  Extending
       (extend-type string
         Catable
         (cat [this other]
           (str this other)))

       (cat sound1 sound2)
       ;=> “MeowMao”

       (cat sound1 "ZZZZZ")
       ;=> "MeowZZZZZ"




Pseudo-classical underpinnings
            FTW
Pseudo-classical
         Updating
         Person = function(name) {
            this._name = name;
         };

         Person.prototype.getName = function() {
            return this._name;
         };

         var me = new Person(‘Fogus’);
         var you = new Person(‘Cercei’);



How can we add hasBeard to every instance
           now and in the future?
Pseudo-classical
               Updating
               Person = function(name) {
                  this._name = name;
               };

               Person.prototype.getName = function() {
                  return this._name;
               };

               var me = new Person(‘Fogus’);
               var you = new Person(‘Cercei’);



    How can we add hasBeard to every instance
               now and in the future?
Person.prototype.hasBeard = function() { return false };
apply
function
Var Args

 JavaScript          ClojureScript


arguments             & stuff
Var Args

     JavaScript          ClojureScript


   arguments              & stuff




An object that holds
    arguments                a seq
ClojureScript apply
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}
ClojureScript apply
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}




                                   (add-first-two 1 2 3)
                                   ;=> 3
ClojureScript apply
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}




                                   (apply add-first-two [1 2 3])
ClojureScript apply
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}




                                   (apply add-first-two [1 2 3])
ClojureScript apply
    (defn apply
      [f arg-seq]
      (.apply f (to-array arg-seq)))
ClojureScript apply
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}




                                   (apply add-first-two [1 2 3])
                                   ;=> 3
ClojureScript apply
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}




                                   (apply add-first-two (iterate inc 1))
                                   ;=> ?
ClojureScript apply




                                   ∞
                                   (defn add-first-two
                                     [& args]
                                     (+ (first args)
                                        (second args)))




function addFirstTwo() {
  var args = // that slice thing
  return cljs.first(args) +
         cljs.second(args);
}




                                   (apply add-first-two (iterate inc 1))
                                   ;=> ?
ClojureScript apply
    (defn apply
      [f arg-seq]
      (.apply f (to-array arg-seq)))
ClojureScript
           applyTo
• A function stored on ClojureScript functions
 • Only if they have var args
• Compiled to only deal with the args seq at
  the maximum fixed arity
 • This ensures that an infinite seq is not
   realized
ClojureScript apply
    (defn apply
      [f arg-seq]
      (if (.applyTo f)
       (if (<= bounded-count fixed-arity)
         (.apply f (to-array arg-seq))
         (.applyTo f args))
        (.apply f (to-array arg-seq)))
ClojureScript apply
    (defn apply
      [f arg-seq]
      (if (.applyTo f)
       (if (<= bounded-count fixed-arity)
         (.apply f (to-array arg-seq))
         (.applyTo f args))
        (.apply f (to-array arg-seq)))
ClojureScript apply
    (defn apply
      [f arg-seq]
      (if (.applyTo f)
       (if (<= bounded-count fixed-arity)
         (.apply f (to-array arg-seq))
         (.applyTo f args))
        (.apply f (to-array arg-seq)))
ClojureScript apply
    (defn apply
      [f arg-seq]
      (if (.applyTo f)
       (if (<= bounded-count fixed-arity)
         (.apply f (to-array arg-seq))
         (.applyTo f args))
        (.apply f (to-array arg-seq)))
Compiler
Anatomy
Cl
  oju
        re
           D   at
                    a




                        AS
                          T
Analysis
Emission
C6
     4




         JA
           VA
              SC
                 RIP
                       T
Thank
                           You

http://joyofclojure.com
         @fogus
Learn More


•   http://bit.ly/cljs-intro

•   http://boss-level.com/?p=102

•   http://blog.fogus.me/tag/clojurescript

•   http://github.com/clojure/clojurescript
Crockford Hates
 instanceof
Functional Inheritance
   instanceof

    var me   = person({'name' : 'Fogus'});

    me instanceof person;
    //=> false
ClojureScript Loves
  instanceof
Pseudo-classical
instanceof

 var me   = new Person('Fogus');

 me instanceof Person;
 //=> true
ClojureScript
satisfies?
 (defprotocol Catable
   (cat [this other]))

 (deftype Cons [H T]
   Catable
   (cat [_ new-tail] nil))

 (satisfies? Catable (Cons. 1 2))
 ;=> true
tread
Don’t Tread on Me
 Function.prototype.method = function(name, f) {
    this.prototype[name] = f;
    return this;
 };

 Object.method('superior', function(name) {
   var that = function;
   var method = that[name];

   return function() {
      return method.apply(that, arguments);
   };
 });
ClojureScript Gently
       Caresses
Object & Function
  as One Might Caress
 the finest Fabergé Egg
Look with your eyes,
not with your hands
  var inherits = function(child, parent) {
    function tmp() {};
    tmp.prototype = parent.prototype;

       child._super = parent.prototype;
       child.prototype = new tmp();
       child.prototype.constructor = child;
  };
Var Args



       JavaScript               ClojureScript
function stuffToArray() {       (defn stuff->seq
  // create an array of stuff     [& stuff]
}                                 stuff)

stuffToArray(1,2,3,4);          (stuff->seq 1 2 3 4)
//=> [1,2,3,4]                  ;=> (1 2 3 4)
Var Args



       JavaScript               ClojureScript
function stuffToArray() {       (defn stuff->seq
  // create an array of stuff     [& stuff]
}                                 stuff)

stuffToArray(1,2,3,4);          (stuff->seq 1 2 3 4)
//=> [1,2,3,4]                  ;=> (1 2 3 4)
Var Args



               JavaScript                         ClojureScript
function stuffToArray() {                         (defn stuff->seq
  return Array.prototype.slice.call(arguments);     [& stuff]
}                                                   stuff)

stuffToArray(1,2,3,4);                            (stuff->seq 1 2 3 4)
//=> [1,2,3,4]                                    ;=> (1 2 3 4)
Compiler Macros
• Operate in the compiler only
 • Analysis phase
• Written in Clojure
• Allows shadowing of fns
 • Operates according to a fix point

ClojureScript Anatomy

  • 1.
  • 6.
  • 7.
  • 8.
    Primacy of Semantics I also regard syntactical problems as essentially irrelevant to programming languages at their present stage ... the urgent task in programming languages is to explore the field of semantic possibilities. — Christopher Strachey - “Fundamental Concepts in Programming Languages”
  • 9.
    JavaScript has muchin common with Scheme. It is a dynamic language. It has a flexible datatype (arrays) that can easily simulate s-expressions. And most importantly, functions are lambdas. http://javascript.crockford.com/little.html
  • 10.
    Power Points • Reach • browser, shell, mobile, databases • First-class functions • Prototypal inheritance • Closures • Literal syntax
  • 12.
  • 13.
  • 17.
  • 18.
    JavaScript • Safety through convention
  • 19.
    JavaScript • Safety through convention • Rampant mutation
  • 20.
    JavaScript • Safety through convention • Rampant mutation • Globals
  • 21.
    JavaScript • Safety through convention • Rampant mutation • Globals • this
  • 22.
    JavaScript • Safety through convention • Rampant mutation • Globals • this • Truthiness
  • 23.
    JavaScript • Safety through convention • Rampant mutation • Globals • this • Truthiness • Objects make poor modules
  • 24.
    JavaScript • Safety through convention • Rampant mutation • Globals • this • Truthiness • Objects make poor modules
  • 25.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Globals • this • Truthiness • Objects make poor modules
  • 26.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Low Compression Potential • Globals • this • Truthiness • Objects make poor modules
  • 27.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Low Compression Potential • Globals • Limited data formats • this • Truthiness • Objects make poor modules
  • 28.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Low Compression Potential • Globals • Limited data formats • this • Limited abstractions • Truthiness • Objects make poor modules
  • 29.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Low Compression Potential • Globals • Limited data formats • this • Limited abstractions • Truthiness • == • Objects make poor modules
  • 30.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Low Compression Potential • Globals • Limited data formats • this • Limited abstractions • Truthiness • == • Objects make poor modules • Optional semicolons
  • 31.
    JavaScript • Safety through convention • Callbacks • Rampant mutation • Low Compression Potential • Globals • Limited data formats • this • Limited abstractions • Truthiness • == • Objects make poor modules • Optional semicolons • Missing `new`
  • 37.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; function init(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 38.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; function init(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 39.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; function init(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 40.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; function init(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 41.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; var init = function(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 42.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; var init = function(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 43.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; var init = function(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 44.
    my = my|| {}; my.awesome = my.awesome || {}; my.awesome.lib = my.awesome.lib || {}; my.awesome.lib = (function(){ var that = {}; var init = function(){ /* do something */ }; that.foo = true; that.init = init; return that; }()); my.awesome.lib.frob = (function($){ function privateFun(){ /* do something */ } return function() { /* do something with $ */ };
  • 47.
    Google Closure • Standardlibrary • Dependency system • Compiler/minifier (GClosure) • Templating language • 1 kajillion man-hours of effort
  • 48.
    Google Closure • Standardlibrary • Dependency system • Compiler/minifier (GClosure) • Templating language • 1 beellion man-hours of effort
  • 52.
    convention convention convention convention convention
  • 53.
    Primacy of Syntax one could say that all semantics is being represented as syntax ... semantics has vanished entirely to be replaced with pure syntax. — John Shutt - “Primacy of Syntax”
  • 54.
  • 55.
  • 57.
  • 58.
    ECMAScript.Next JSModule nodules modules.js curl.js
  • 59.
  • 60.
    Namespaces fogus = fogus|| {}; fogus.my = fogus.my || {}; fogus.my.lib = fogus.my.lib || {};
  • 61.
    Namespaces (ns fogus.my.lib) (defn frobnicate[] :frobbed!) goog.provide(‘fogus.my.lib) ; fogus.my.lib = function() { return “□ :frobbed!” };
  • 62.
  • 63.
    Take your pick (nsfogus.my.lib) goog.provide(‘fogus.my.lib’); fogus = fogus || {}; fogus.my = fogus.my || {}; fogus.my.lib = fogus.my.lib || {};
  • 64.
    Take your pick (nsfogus.my.lib) goog.provide(‘fogus.my.lib’); fogus = fogus || {}; fogus.my = fogus.my || {}; fogus.my.lib = fogus.my.lib || {};
  • 65.
  • 66.
    Abstractions • Protocols atthe bottom • ISeq, IMap, ILookup, IDeref, etc. • Realizing powerful immutable types • Map, List, Vector, etc. • Extended to JavaScript • strings, null, arrays, etc.
  • 67.
    JavaScript the Parts
  • 68.
    Functional Inheritance Pattern • Private data • Access to super methods • Missing new safe
  • 69.
    Functional Inheritance Pattern var person = function(spec) { var that = {}; that.getName = function() { var me = person({'name' : 'Fogus'}); return spec.name; me.getName() }; //=> 'Fogus' return that; }; var man = function(spec) { var that = person(spec); var super_getName = that.superior('getName'); var me = man({'name' : 'Fogus'}); that.getName = function() { me.getName() return "Mr. " + super_getName(); //=> 'Mr. Fogus' }; return that; };
  • 70.
    Functional Inheritance Pattern Dangers • Harder to minify • Larger memory footprint • Cannot update instances • Eliminates instanceof • Mucks with Function.prototype and Object.prototype in an unsafe way
  • 71.
    Pseudo-classical Inheritance Pattern Person = function(name) { this._name = name; }; var me = new Person('Fogus'); Person.prototype.getName = function() { me.getName() return this._name; //=> 'Fogus' }; Man = function(name) { Person.call(this, name); }; inherits(Man, Person); var me = new Man('Fogus'); me.getName() Man.prototype.getName = function() { //=> 'Mr. Fogus' return "Mr. " + Man._super.getName.call(this); };
  • 72.
    Pseudo-classical Inheritance Pattern • Harder Easier to minify • Larger Smaller memory footprint • Cannot Can update instances • Eliminates instanceof • Mucks with Clean Function.prototype and Object.prototype
  • 73.
    Safe Extension String.prototype.cljs$core$first =... Object.prototype.my$lib$first = ...
  • 74.
  • 75.
  • 76.
  • 77.
    Functional Inheritance Inlining var person = function(spec) { var myName = me.getName(); var that = {}; var sig = signature({‘name’ : myName}); sig.toString(); that.getName = function() { //=> ‘Sent from teh Fogus iPhone’ return spec.name; }; return that; };
  • 78.
    Functional Inheritance Inlining var person = function(spec) { var myName = me.getName(); var that = {}; var sig = signature({‘name’ : myName}); sig.toString(); that.getName = function() { //=> ‘Sent from teh Fogus iPhone’ return spec.name; }; return that; }; ?
  • 79.
    Functional Inheritance Inlining var person = function(spec) { var myName = me.getName(); var that = {}; var sig = signature({‘name’ : myName}); sig.toString(); that.getName = function() { //=> ‘Sent from teh Fogus iPhone’ return spec.name; }; return that; }; var sig = signature({‘name’ : me.getName()}); sig.toString(); //=> ‘Sent from teh Fogus iPhone’
  • 80.
  • 81.
    Pseudo-classical Inlining Person =function(name) { this._name = name; var myName = me.getName(); }; var sig = new Signature(myName); sig.toString(); Person.prototype.getName = function() { //=> ‘Sent from teh Fogus iPhone’ return this._name; }; ?
  • 82.
    Pseudo-classical Inlining Person =function(name) { this._name = name; var myName = me.getName(); }; var sig = new Signature(myName); sig.toString(); Person.prototype.getName = function() { //=> ‘Sent from teh Fogus iPhone’ return this._name; }; var sig = new Signature(me._name); sig.toString(); //=> ‘Sent from teh Fogus iPhone’
  • 83.
  • 84.
    Functional Inheritance Renaming var person = function(spec) { var that = {}; that.getName = function() { return spec.name; }; return that; }; var man = function(spec) { var that = person(spec); var super_getName = that.superior(‘getName’); that.getName = function() { return "Mr. " + super_getName(); }; return that; };
  • 85.
    Functional Inheritance Renaming var person = function(spec) { var that = {}; that.getName = function() { return spec.name; }; return that; }; var man = function(spec) { var that = person(spec); var super_getName = that.superior(‘getName’); that.getName = function() { return "Mr. " + super_getName(); }; return that; };
  • 86.
  • 87.
    Pseudo-classical Renaming Person = function(name) { this._name = name; }; Person.prototype.getName = function() { return this._name; }; Man = function(name) { Person.call(this, name); }; inherits(Man, Person); Man.prototype.getName = function() { return "Mr. " + Man._super.getName.call(this); };
  • 88.
    Pseudo-classical Renaming Person = function(name) { this._name = name; }; Person.prototype.o = function() { return this._name; }; Man = function(name) { Person.call(this, name); }; inherits(Man, Person); Man.prototype.getName = function() { return "Mr. " + Man._super.o.call(this); };
  • 89.
  • 90.
    Dead-code Elimination Intro (let [a 1 b 2 a b] a) ;=> 2
  • 91.
    Dead-code Elimination Intro (function (){ (let [a 1 var a__847 = 1; b 2 var b__848 = 2; a b] var a__849 = b__848; a) return a__849; ;=> 2 })();
  • 92.
    Dead-code Elimination Intro (function (){ (let [a 1 var a__847 = 1; b 2 var b__848 = 2; a b] var a__849 = b__848; a) return a__849; ;=> 2 })(); ?
  • 93.
    Dead-code Elimination Intro (function (){ (let [a 1 var a__847 = 1; b 2 var b__848 = 2; a b] var a__849 = b__848; a) return a__849; ;=> 2 })(); 2
  • 94.
    Dead-code Elimination Intro (function (){ (let [a 1 var a__847 = 1; b 2 var b__848 = 2; a b] var a__849 = b__848; a) return a__849; ;=> 2 })();
  • 95.
    Functional Inheritance Dead-code var person = function(spec) { var that = {}; var hasBeard = false; that.getName = function() { return spec.name; }; return that; }; var man = function(spec) { var that = person(spec); var super_getName = that.superior(‘getName’); that.getName = function() { return "Mr. " + super_getName(); }; return that; };
  • 96.
    Functional Inheritance Dead-code var person = function(spec) { var that = {}; var hasBeard = false; that.getName = function() { return spec.name; }; return that; }; var man = function(spec) { var that = person(spec); All good var super_getName = that.superior(‘getName’); Right? that.getName = function() { return "Mr. " + super_getName(); }; return that; };
  • 97.
    Functional Inheritance Dead-code var person = function(spec) { var that = {}; var hasBeard = false; that.getName = function() { Cursed return spec.name; }; return that; Closures! }; var man = function(spec) { var that = person(spec); var super_getName = that.superior(‘getName’); that.getName = function() { return "Mr. " + super_getName(); }; return that; };
  • 98.
  • 99.
    Pseudo-classical Dead-code Person= function(name) { this._name = name; this._hasBeard = false; }; Person.prototype.getName = function() { return this._name; }; Man = function(name) { Person.call(this, name); }; inherits(Man, Person); Man.prototype.getName = function() { return "Mr. " + Man._super.getName.call(this); };
  • 100.
    Pseudo-classical Dead-code Person= function(name) { this._name = name; this._hasBeard = false; }; Person.prototype.getName = function() { return this._name; }; Man = function(name) { Person.call(this, name); }; inherits(Man, Person); Man.prototype.getName = function() { return "Mr. " + Man._super.getName.call(this); };
  • 101.
    Pseudo-classical Dead-code Person= function(name) { this._name = name; }; kthxbai Person.prototype.getName = function() { return this._name; }; Man = function(name) { Person.call(this, name); }; inherits(Man, Person); Man.prototype.getName = function() { return "Mr. " + Man._super.getName.call(this); };
  • 102.
    There’s more tolife than this
  • 103.
    Memory Footprint • Crockford • Closure per-method, per-type • Leaky (holds a reference to all variables) • Pseudo-classical • No closures needed
  • 104.
  • 105.
    Instance Updating • Problem • How to update every instance in the system with new behavior?
  • 106.
    Functional Inheritance Updating var person = function(spec) { var that = {}; that.getName = function() { return spec.name; }; return that; }; var me = person({'name' : 'Fogus'}); var you = person({'name' : 'Cersei'}); How can we add hasBeard to every instance now and in the future?
  • 107.
    Functional Inheritance Updating var person = function(spec) { var that = {}; that.getName = function() { return spec.name; }; return that; }; var me = person({'name' : 'Fogus'}); var you = person({'name' : 'Cersei'}); How can we add hasBeard to every instance now and in the future? One at a time... every single time
  • 108.
  • 109.
    ClojureScript Extending (defprotocol Catable (cat [this other])) (def sound1 "Meow") (def sound2 "Mao") (cat sound1 sound2) ; ASPLODE! How can we allow cat to work with every instance now and in the future?
  • 110.
    ClojureScript Extending (extend-type string Catable (cat [this other] (str this other))) (cat sound1 sound2) ;=> “MeowMao” (cat sound1 "ZZZZZ") ;=> "MeowZZZZZ" Pseudo-classical underpinnings FTW
  • 111.
    Pseudo-classical Updating Person = function(name) { this._name = name; }; Person.prototype.getName = function() { return this._name; }; var me = new Person(‘Fogus’); var you = new Person(‘Cercei’); How can we add hasBeard to every instance now and in the future?
  • 112.
    Pseudo-classical Updating Person = function(name) { this._name = name; }; Person.prototype.getName = function() { return this._name; }; var me = new Person(‘Fogus’); var you = new Person(‘Cercei’); How can we add hasBeard to every instance now and in the future? Person.prototype.hasBeard = function() { return false };
  • 114.
  • 115.
  • 116.
    Var Args JavaScript ClojureScript arguments & stuff
  • 117.
    Var Args JavaScript ClojureScript arguments & stuff An object that holds arguments a seq
  • 118.
    ClojureScript apply (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); }
  • 119.
    ClojureScript apply (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); } (add-first-two 1 2 3) ;=> 3
  • 120.
    ClojureScript apply (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); } (apply add-first-two [1 2 3])
  • 121.
    ClojureScript apply (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); } (apply add-first-two [1 2 3])
  • 122.
    ClojureScript apply (defn apply [f arg-seq] (.apply f (to-array arg-seq)))
  • 123.
    ClojureScript apply (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); } (apply add-first-two [1 2 3]) ;=> 3
  • 124.
    ClojureScript apply (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); } (apply add-first-two (iterate inc 1)) ;=> ?
  • 125.
    ClojureScript apply ∞ (defn add-first-two [& args] (+ (first args) (second args))) function addFirstTwo() { var args = // that slice thing return cljs.first(args) + cljs.second(args); } (apply add-first-two (iterate inc 1)) ;=> ?
  • 126.
    ClojureScript apply (defn apply [f arg-seq] (.apply f (to-array arg-seq)))
  • 128.
    ClojureScript applyTo • A function stored on ClojureScript functions • Only if they have var args • Compiled to only deal with the args seq at the maximum fixed arity • This ensures that an infinite seq is not realized
  • 129.
    ClojureScript apply (defn apply [f arg-seq] (if (.applyTo f) (if (<= bounded-count fixed-arity) (.apply f (to-array arg-seq)) (.applyTo f args)) (.apply f (to-array arg-seq)))
  • 130.
    ClojureScript apply (defn apply [f arg-seq] (if (.applyTo f) (if (<= bounded-count fixed-arity) (.apply f (to-array arg-seq)) (.applyTo f args)) (.apply f (to-array arg-seq)))
  • 131.
    ClojureScript apply (defn apply [f arg-seq] (if (.applyTo f) (if (<= bounded-count fixed-arity) (.apply f (to-array arg-seq)) (.applyTo f args)) (.apply f (to-array arg-seq)))
  • 132.
    ClojureScript apply (defn apply [f arg-seq] (if (.applyTo f) (if (<= bounded-count fixed-arity) (.apply f (to-array arg-seq)) (.applyTo f args)) (.apply f (to-array arg-seq)))
  • 133.
  • 139.
    Cl oju re D at a AS T
  • 142.
  • 148.
  • 153.
    C6 4 JA VA SC RIP T
  • 157.
    Thank You http://joyofclojure.com @fogus
  • 158.
    Learn More • http://bit.ly/cljs-intro • http://boss-level.com/?p=102 • http://blog.fogus.me/tag/clojurescript • http://github.com/clojure/clojurescript
  • 160.
  • 161.
    Functional Inheritance instanceof var me = person({'name' : 'Fogus'}); me instanceof person; //=> false
  • 162.
  • 163.
    Pseudo-classical instanceof var me = new Person('Fogus'); me instanceof Person; //=> true
  • 164.
    ClojureScript satisfies? (defprotocol Catable (cat [this other])) (deftype Cons [H T] Catable (cat [_ new-tail] nil)) (satisfies? Catable (Cons. 1 2)) ;=> true
  • 165.
  • 166.
    Don’t Tread onMe Function.prototype.method = function(name, f) { this.prototype[name] = f; return this; }; Object.method('superior', function(name) { var that = function; var method = that[name]; return function() { return method.apply(that, arguments); }; });
  • 167.
    ClojureScript Gently Caresses Object & Function as One Might Caress the finest Fabergé Egg
  • 168.
    Look with youreyes, not with your hands var inherits = function(child, parent) { function tmp() {}; tmp.prototype = parent.prototype; child._super = parent.prototype; child.prototype = new tmp(); child.prototype.constructor = child; };
  • 169.
    Var Args JavaScript ClojureScript function stuffToArray() { (defn stuff->seq // create an array of stuff [& stuff] } stuff) stuffToArray(1,2,3,4); (stuff->seq 1 2 3 4) //=> [1,2,3,4] ;=> (1 2 3 4)
  • 170.
    Var Args JavaScript ClojureScript function stuffToArray() { (defn stuff->seq // create an array of stuff [& stuff] } stuff) stuffToArray(1,2,3,4); (stuff->seq 1 2 3 4) //=> [1,2,3,4] ;=> (1 2 3 4)
  • 171.
    Var Args JavaScript ClojureScript function stuffToArray() { (defn stuff->seq return Array.prototype.slice.call(arguments); [& stuff] } stuff) stuffToArray(1,2,3,4); (stuff->seq 1 2 3 4) //=> [1,2,3,4] ;=> (1 2 3 4)
  • 172.
    Compiler Macros • Operatein the compiler only • Analysis phase • Written in Clojure • Allows shadowing of fns • Operates according to a fix point

Editor's Notes

  • #2 \n
  • #3 * One of the great stories in the history of hacking\n* Right up there with that guy who used autoconfig properly\n
  • #4 \n
  • #5 * If JavaScript is so cool, then why target it? Why not use it?\n
  • #6 * The meaning is king. \n* Anything that can be done in CLJS can be done with JS\n * This is the root of all Turing completeness arguments\n\n
  • #7 * For the purposes of writing Little Schemer only\n
  • #8 Everyone implements classes. :-(\n
  • #9 * first-class functions\n* prototypal\n* closures\n* literals\n
  • #10 \n
  • #11 \n
  • #12 \n
  • #13 \n
  • #14 \n
  • #15 \n
  • #16 \n
  • #17 \n
  • #18 \n
  • #19 \n
  • #20 \n
  • #21 \n
  • #22 \n
  • #23 \n
  • #24 \n
  • #25 \n
  • #26 \n
  • #27 * Really this is the only snarky language joke I&amp;#x2019;ll say all day. \n
  • #28 * This is Douglass Crockford\n* Seems like a nice guy\n* Wrote a book about using only the nice parts of JS\n
  • #29 * But there is something sinister about this advice!\n
  • #30 * How is JavaScript like a Russian novel?\n
  • #31 \n
  • #32 * Semicolons\n
  • #33 * Namespacing\n
  • #34 * Closure pattern\n
  • #35 * LET pattern\n
  • #36 * VAR\n
  • #37 * privates\n
  • #38 * publics\n
  • #39 * And after all of that... you can add some functionality.\n
  • #40 * You need to introduce thousands of characters before anything happens.\n
  • #41 \n
  • #42 \n
  • #43 Anyone have experience with GClosure? It&amp;#x2019;s tough to follow the conventions. I wrote every function/form in js *before* I wrote the cljs impl.\n
  • #44 \n
  • #45 \n
  • #46 \n
  • #47 * conventions conventions conventions\n* It&amp;#x2019;s too much to think about sometimes, but people will get used to *anything*\n* But you&amp;#x2019;ve still not yet solved the problem at hand.\n* JS with a rabid adherence to conventions is 84% as safe as Haskell!\n
  • #48 * All useful semantics become syntax.\n* In JS, its syntax betrays its semantics because intent is buried in idiom, verbosity, and safety checks.\n* CLJS (and LISP) leave syntax as an open set in order to allow one to build the syntax to match the semantics.\n\n| Isn&apos;t the semantics more important the syntax?\n\ngenerally speaking, if this were true, we would not see the syntax-fixation\nthat the whole industry is built on. syntax _distinguishes_ programming\nlanguages from each other; the semantics is only a question of how much of\nthe syntax you need to implement it. e.g., if CFRONT can produce C code\nfrom C++, so can a human. syntax can help automate the expression of the\nsemantics in very important ways, or serve to frustrate the same process.\nhowever, certain operations are possible (that is, sufficiently easy) on\ncertain syntaxes, which leads me to the more specific interpretation.\n
  • #49 * Let&amp;#x2019;s talk a moment to talk about CoffeeScript\n* Enjoyed my time\n* JS the good parts -- eliminates much of the ceremony, many edge cases (while introducing some of its own)\n* But maybe we need something more...\n
  • #50 Asynchronous - DOM - Constant serialization - Limited resources and slow pipes - Hostile environment\n
  • #51 \n
  • #52 \n
  • #53 * Because you can!\n* Although there are many flavors, they tend to a common pattern...\n
  • #54 * This is a namespaced JS function.\n* Nested objects\n
  • #55 \n
  • #56 * This leads me into a nice discussion about compression potential...\n
  • #57 * What do I mean?\n* Not golfing!\n
  • #58 * You can get fairly compressed in the second example, but this is indicative only of this problem, and not in the language itself.\n* CoffeeScript doesn&amp;#x2019;t fix this. It shaves characters, but that&amp;#x2019;s all.\n
  • #59 \n
  • #60 * Why so many class systems? \n* Because you can!\n* Many suffer from a lack of safety or composability\n
  • #61 \n
  • #62 \n
  • #63 \n
  • #64 \n
  • #65 \n
  • #66 \n
  • #67 * Clojure ensures safety by...\n
  • #68 * To Crockford&amp;#x2019;s credit, his is better encapsulated.\n
  • #69 \n
  • #70 \n
  • #71 \n
  • #72 \n
  • #73 \n
  • #74 \n
  • #75 \n
  • #76 \n
  • #77 \n
  • #78 \n
  • #79 \n
  • #80 \n
  • #81 \n
  • #82 \n
  • #83 \n
  • #84 \n
  • #85 \n
  • #86 \n
  • #87 \n
  • #88 \n
  • #89 \n
  • #90 \n
  • #91 \n
  • #92 \n
  • #93 \n
  • #94 \n
  • #95 \n
  • #96 \n
  • #97 \n
  • #98 \n
  • #99 \n
  • #100 \n
  • #101 \n
  • #102 \n
  • #103 \n
  • #104 \n
  • #105 \n
  • #106 \n
  • #107 \n
  • #108 \n
  • #109 * functions cause complication\n
  • #110 \n
  • #111 \n
  • #112 \n
  • #113 \n
  • #114 \n
  • #115 \n
  • #116 \n
  • #117 \n
  • #118 \n
  • #119 \n
  • #120 \n
  • #121 \n
  • #122 \n
  • #123 \n
  • #124 \n
  • #125 \n
  • #126 \n
  • #127 \n
  • #128 \n
  • #129 \n
  • #130 * Simple as CLJ\n
  • #131 * Compiler Macros\n
  • #132 * AST\n
  • #133 * AST\n
  • #134 \n
  • #135 * Well, this is what I&amp;#x2019;ve already talked about\n
  • #136 \n
  • #137 * People are already using the analyzer\n* typing, Marg, etc.\n
  • #138 \n
  • #139 \n
  • #140 \n
  • #141 * AWESOME Syntax Tree!!!\n
  • #142 \n
  • #143 \n
  • #144 \n
  • #145 * Get rid of everything but the emitter\n* Remember it takes an AST\n
  • #146 * Parser generates an AST in CLJS format\n
  • #147 * Parser generates an AST in CLJS format\n
  • #148 Rock On!\n
  • #149 Make something amazing\n
  • #150 Possibilities are Limitless\n
  • #151 \n
  • #152 \n
  • #153 \n
  • #154 \n
  • #155 \n
  • #156 \n
  • #157 \n
  • #158 \n
  • #159 \n
  • #160 \n
  • #161 \n
  • #162 \n
  • #163 \n
  • #164 \n
  • #165 \n
  • #166 * TODO: More talking points here --- example?\n