Live data from Hacker News

CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

jashkenas.github.com

61–67 of 67 posts

Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

#61

CoffeeScript's now up to 0.1.3, which includes --interactive to launch a CoffeeScript REPL, and --run to compile and execute scripts in a single pass. Both options depend on a working Narwhal installation.

Sweet! Now, add a minifying pass after compilation for deployment and you'll have created a dream platform for client-side scripting (-: edit: another suggestion since one of your goals is terseness: you may want to alias "prototype" to "proto". edit2: as much as I like the column for asignment (present in both JS itself and Ruby 1.9), I'm not really fan of the +:, -:, etc. combined operators, at least in a math cont…

Yeah, I think you're right about the other operators -- I've just pushed a commit that puts them back to +=, -=, ||=, and so on. Thanks.

Underscore is going to stay unrelated, but there's no reason that you couldn't use it from CoffeeScript, to great effect.

Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

#62
post #49

Earlier quoted context omitted.

a: 1 b: 2 obj: { a: 1 b: 2 } Quite right, and internally, both kinds of assignment compile into a CoffeeScript AssignNode. The latter is just tagged as occurring within an object literal. Having the commas be optional in multiline objects also helps make both kinds of assignment look identical. (And I'm calling it assignment because saying "binding" in JavaScript usually means that you're binding a function to a "thi…

Any chance you'll allow equal sign as well as colon? For all of us coders conditioned by years of programming to automatically use "="... Looks beautiful, in any case.

Sure, why not. They can be interchangeable. It's in the latest commit, and will go out with the next release.

Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

#63
post #49

Earlier quoted context omitted.

Any chance you'll allow equal sign as well as colon? For all of us coders conditioned by years of programming to automatically use "="... Looks beautiful, in any case.

Sure, why not. They can be interchangeable. It's in the latest commit, and will go out with the next release.

Cool, thanks!

Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

#64
post #56

Earlier quoted context omitted.

Be careful with __proto__, it's non-standard and will break in some engines.

To get the equivalent of __proto__ that works in every engine see goog.inherits from Closure.

Thanks for the pointer. I've pushed a commit that avoids __proto__, and produces this...

CoffeeScript:

    Horse extends Animal
JavaScript:

    Horse.__superClass__ = Animal.prototype;
    Horse.prototype = new Animal();
    Horse.prototype.constructor = Horse;
Calling super uses the __superClass__ reference. I hate to add it as an enumerable property, but there doesn't seem to be any other way to get at it, and at least it's on the class and not the object.

Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

#65
post #38

Earlier quoted context omitted.

Yeah, all the good extensions are taken -- .cof and .cfs are already other things as well. None of the tooling in the compiler cares about what extension you use: you can call it .coffeescript if you'd like. I'm going to stick to .cs for the parallel to .js for the time being.

.coffee seems an appropriate balance between overloading the namespace and a too-long common string in one's directory. The 2- and 3-letter extension tyranny must stopped!

Nice idea. I've changed the official extension from ".cs" to ".coffee", and it'll go out with the next release. Thanks.

Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN

#67
Very nice. How about language-level support for asynchronous operations (like the async monad in F#)

    async update_table:q =>
        r1,err = xhr('http://somewhere?q='+q)
        if err then
            $('error').innerHTML = err
            return.
        r2,err = xhr('http://somewhere-else?q='+r1)

        if err then
            $('error').innerHTML = err
            return.

        $('result').innerHTML = r2
        .
could be the equivalent of something like:

    function update_table(q) {
        var on_error = function(err) { $('error').innerHTML = err; }
        
        doXHR('http://somewhere?q='+q
            ,function(r1){
                doXHR('http://somewhere-else?q='+r1,function(r2){
                    $('result').innerHTML = r2;
                },err));
            },err);
        );
        
    }
Post reply on HN