Skip to content
caseywebdev edited this page Sep 7, 2012 · 22 revisions

Size / Speed

$ git log -1 --oneline
79492aa CoffeeScript 1.3.3

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

$ cake loc 2659

$ cake bench Lex 1520 ms (24184 tokens) Rewrite 186 ms (26925 tokens) Parse 368 ms Compile 285 ms (149588 chars) total 2359 ms

$ git log -1 --oneline
dcff170 0.7.2

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

$ coke loc 2499

$ coke bench Lex 469 ms (26005 tokens) Rewrite 200 ms (31203 tokens) Parse 539 ms (26737 nodes) Compile 341 ms (174118 chars) TOTAL 1549 ms

Temporary Variables

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

$ coffee -bce '[i for i in a]'
// Generated by CoffeeScript 1.3.3
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 -bce '[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 -bce 'a > b() > c; d > e() > f'
// Generated by CoffeeScript 1.3.3
var _ref, _ref1;

(a > (_ref = b()) && _ref > c);

(d > (_ref1 = e()) && _ref1 > f);

$ coco -bce 'a > b() > c; d > e() > f'
var __ref;
a > (__ref = b()) && __ref > c;
d > (__ref = e()) && __ref > f;
$ coffee -bce 'r = for k of o then arguments'
// Generated by CoffeeScript 1.3.3
var k, r;

r = (function() { var _results; _results = []; for (k in o) { _results.push(arguments); } return _results; }).apply(this, arguments);

$ coco -bce 'r = for k in o then arguments'
var k, r, __res, __i, __ref, __len;
__res = [];
for (__i = 0, __len = (__ref = o).length; __i < __len; ++__i) {
k = __ref[__i];
__res.push(arguments);
}
r = __res;

Compile Errors

variable safety

$ coffee -bce 'Math += 1'
// Generated by CoffeeScript 1.3.3

Math += 1;

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

duplicate property

$ coffee -bce '{0, "0"}'
// Generated by CoffeeScript 1.3.3

({
  0: 0,
  "0": "0"
});

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

line number

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

$ coco -bce '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 -bce '[]()'
// Generated by CoffeeScript 1.3.3

[]();

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

invalid regex

$ coffee -bce '/+/'
// Generated by CoffeeScript 1.3.3

/+/;

$ coco -bce '/+/'
SyntaxError: Invalid regular expression: /+/: Nothing to repeat on line 1

invalid identifier

$ coffee -bce '$= 1'
// Generated by CoffeeScript 1.3.3
var $;

$ = 1;

$ coco -bce '$= 1'
Error: Parse error on line 1: Unexpected '$'

$ node -e '$= 1'

undefined:1

^
SyntaxError: Unexpected token ILLEGAL

invalid operand

$ coffee -bce '0 instanceof 1'
// Generated by CoffeeScript 1.3.3

0 instanceof 1;

$ coco -bce '0 instanceof 1'
SyntaxError: invalid instanceof operand on line 1

$ node -e '0 instanceof 1'

undefined:1

^
TypeError: Expecting a function in instanceof check, but got 0

Syntax Consistency

@foothis.foo

$ coffee -bce '{@foo}'
// Generated by CoffeeScript 1.3.3

({ foo: this.foo });

$ coffee -bce '{this.foo}' Error: Parse error on line 1: Unexpected 'THIS' ...

$ coco -bce '{@foo}; {this.foo}'
({
foo: this.foo
});
({
foo: this.foo
});

implicit call/object interaction

$ coffee -bce 'f k: v, a + b'
Error: Parse error on line 1: Unexpected '+'
...

$ coffee -bce 'k: f a, ->' Error: Parse error on line 1: Unexpected ',' ...

$ coco -bce 'f k: v, a + b'
f({
k: v
}, a + b);

$ coco -bce 'k: f a, ->' ({ k: f(a, function(){}) });

$ coffee -bcs
  f
    k: v
    a

// Generated by CoffeeScript 1.3.3

f({ k: v }, a);

$ coffee -bcs f a k: v

Error: Parse error on line 2: Unexpected 'INDENT' ...

$ coco -bcs
f do
k: v
a

f({ k: v }, a);

$ coco -bcs f do a k: v

f(a, { k: v });

line continuation

$ coffee -bcs
  if a then b
       else c

Error: Parse error on line 1: Unexpected 'INDENT' ...

$ coco -bcs
if a then b
else c

if (a) { b; } else { c; }

Clone this wiki locally