Skip to content
satyr edited this page May 27, 2011 · 22 revisions

Size/Speed

$ git log -1 --oneline
9e4fa02 CoffeeScript 1.1.1

$ ls -sk extras/co*.js 160 extras/coffee-script.js

$ cake loc 2418

$ cake bench Lex 1597 ms (21836 tokens) Rewrite 220 ms (24350 tokens) Parse 293 ms Compile 193 ms (132096 chars) total 2303 ms

$ git log -1 --oneline
7e5344b 0.5.3

$ ls -sk extras/co*.js 132 extras/coco.js

$ coke loc 2322

$ coke bench Lex 421 ms (23770 tokens) Rewrite 170 ms (27709 tokens) Parse 187 ms (24085 nodes) Compile 193 ms (140362 chars) TOTAL 971 ms

Temporary Variables

Coco uses them more wisely than Coffee, making generated code cleaner and/or faster.

$ coffee -bpe '[i for i in a]'
var i;
[
  (function() {
    var _i, _len, _results;
    _results = [];
    for (_i = 0, _len = a.length; _i < _len; _i++) {
      i = a[_i];
      _results.push(i);
    }
    return _results;
  })()
];
$ coco -bpe '[i for i of a]'
var i;
[
  (function(){
    var _i, _ref, _len, _results = [];
    for (_i = 0, _len = (_ref = a).length; _i < _len; ++_i) {
      i = _ref[_i];
      _results.push(i);
    }
    return _results;
  }())
];
$ coffee -bpe 'a < b() < c; d > e() > f'
var _ref, _ref2;
(a < (_ref = b()) && _ref < c);
(d > (_ref2 = e()) && _ref2 > f);
$ coco -bpe 'a < b() < c; d > e() > f'
var _ref;
a < (_ref = b()) && _ref < c;
d > (_ref = e()) && _ref > f;
$ coffee -bpe '=> this'
var __bind = function(fn, me){ ... };
__bind(function() {
  return this;
}, this);
$ coco -bpe '~> this'
var _this = this;
(function(){
  return _this;
});
$ coffee -bpe 'r = for k of o then arguments'
var k, r;
r = (function() {
  var _results;
  _results = [];
  for (k in o) {
    _results.push(arguments);
  }
  return _results;
}).apply(this, arguments);
$ coco -bpe 'r = for k in o then arguments'
var k, r;
r = (function(_args){
  var _results = [];
  for (k in o) {
    _results.push(_args);
  }
  return _results;
}(arguments));

Compile Errors

variable safety

$ coffee -bpe 'Math += 1'
Math += 1;

$ coco -bpe 'Math += 1'
SyntaxError: assignment to undeclared variable "Math" on line 1

duplicate name

$ coffee -bpe 'a:1, a:2'
({
  a: 1,
  a: 2
});

$ coco -bpe 'a:1, a:2'
SyntaxError: duplicate property name "a" on line 1

line number

$ coffee -bpe 'x = (return)'
SyntaxError: cannot use a pure statement in an expression.
...

$ coco -bpe 'x = (return)'
SyntaxError: inconvertible statement on line 1
...

space/tab contamination

$ cat space_tab.coffee
if 0
        console.log 1
        console.log 2

$ coffee space_tab.coffee
2

$ coco space_tab.coffee
Failed at: space_tab.coffee

SyntaxError: contaminated indent %09 on line 2

misdentation

$ cat misdent.coffee
if 0
    console.log 1
  console.log 2

$ coffee misdent.coffee
2

$ coco misdent.coffee
Failed at: misdent.coffee

SyntaxError: unmatched dedent (2 for 4) on line 3

invalid call

$ coffee -bpe '[]()'
[]();

$ coco -bpe '[]()'
SyntaxError: invalid callee on line 1

invalid regex

$ coffee -bpe '/+/'
/+/;

$ coco -bpe '/+/'
SyntaxError: Invalid regular expression: /+/: Nothing to repeat on line 1
Clone this wiki locally