Roy

Brian McKenna

Atlassian

JavaScript

Boilerplate

var x = function(a, b, c){
  return a + b + c;
};

Tolerance

x = 100;
// No "var", ruined launch

Complexity

var p1 = Person();
var p2 = new Person();
// Wait... Which should I use?

Dangerous

var two = 1 + true;
console.log(two == "2"); // true

JavaScript

the bad parts
Ubiquity
JavaScript
without the
JavaScript
Compilation

http://altjs.org/

altJS List

CoffeeScript Coco Contracts.coffee Jack JS11 Sibilant Kaffeine Move
Zedscript ADsafe Caja Dojo FBJS Jacaranda Gatekeeper SafeJS Script#
MileScript Mascara Roy Prefix Streamline.js fork TameJS mobl StratifiedJS
NarrativeJS jwacs Jscex ContextJS Cycript Objective-J JS2 Jangaroo
Flapjax Restrict JavaScript++ Narcissus Traceur HotRuby rb2js Red Quby
PYXC-PJ Pyjamas Skulpt PyCow PyvaScript GWT Java2Script j2js Parenscript
Moby Scheme scheme2js ClojureScript clojurejs Scriptjure edgelisp Ralph
Spock Fargo Ocamljs O'Browser Js_of_ocaml SMLtoJs UHC YHC JSHC Clamato
Smalltalk JTalk Lively Kernel Emscripten mala Clue qb.js Haxe Fantom
Monkey Clue jsc JSIL Opa Fun Ur WebSharper mobl E Sugar Dart Oia
newspeak Quixe Gnusto Logo TIScript tcl.js

Huge

CoffeeScript

brian =
  name: "Brian McKenna" 
  age: 21
var brian;
brian = {
  name: "Brian McKenna",
  age: 21
};
CoffeeScript
           ×           
  OCaml  
Roy
let hundred = 100 
var hundred = 100;
// Won't compile
// console.log ("40" + 2)
let a = [1, 2, 3]
let t = (1, true, "three") 
var a = [1, 2, 3];
var t = [1, true, "three"];
// Explicit
let f x : Number = x


console.log (f 100)
// Won't compile:
// console.log (f "100")
// Explicit
var f = function(x) {
    return x;
};
console.log(f(100));
// Won't compile:
// console.log (f "100")
let plusXY a = a.x + a.y
console.log (plusXY obj)
console.log (plusXY {x: 2, y: 1})
// Won't compile
// plusXY {x: 1, z: 2}
var plusXY = function(a) {
    return a.x + a.y;
};
console.log(plusXY(obj));
console.log(plusXY({
    "x": 2,
    "y": 1
}));
// Won't compile
// plusXY {x: 1, z: 2}
data Option a =
  Some a | None

let noneZero o = match o      
  case (Some s) = s
  case None = 0

noneZero None
// 0
noneZero (Some 1)
// 1
var Some = function(a){this._0 = a;};
var None = function(){};
var noneZero = function(o) {
    return (function() {
        if(o instanceof Some) {
            var s = o._0;
            return s;
        } else if(o instanceof None) {    
            return 0;
        }
    })();
};
noneZero(new None());
// 0
noneZero(new Some(1));
// 1
Monad syntax
let optionMonad = {
  bind: \o f -> match o
    case (Some a) = Some (f a)
    case None     = None
  return: \x -> Some x
}

do optionMonad
  x <- Some 100
  y <- Some 10
  return (x + y)
var optionMonad = {
    "bind": function(x, f) {
        return (function() {
            if(x instanceof Some) {
                var a = x._0;
                return f(a);
            } else if(x instanceof None) {
                return new None();
            }
        })();
    },
    "return": function(x) {
        return new Some(x);
    }
};

(function(){
    var __monad__ = optionMonad;
    return __monad__["bind"](new Some(100), function(x) {
        return __monad__["bind"](new Some(10), function(y) {
            return __monad__["return"](x + y);
        });
    });
})();
Demo
Future
http://roy.brianmckenna.org/
 
https://bitbucket.org/puffnfresh/roy
@puffnfresh
Thanks!