News for hackers. Stuff that matters.
Re:Closure Mode for CoffeeScript by fortes on Friday August 05, 2011 @04:48PM (#2851699)
As a heavy user of Closure Compiler and a fan of CoffeeScript, I love love love the potential here.

@jashkenas -- any thoughts/concerns with this? How likely is it to hit main branch?

Re:Closure Mode for CoffeeScript by jashkenas on Friday August 05, 2011 @05:04PM (#2851767)
Not likely to hit the main branch, as it requires everyone who uses the language to also to use the Google Closure library, as well as the Closure compiler. But as a fork, I think it's brilliant.
Re:Closure Mode for CoffeeScript by fortes on Friday August 05, 2011 @05:07PM (#2851775)
It's an optional mode via command line, no? Opt-in won't require anyone to use closure.
Re:Closure Mode for CoffeeScript by jashkenas on Friday August 05, 2011 @05:25PM (#2851844)
Fair enough ... it's definitely worth considering seriously. I'd probably wait until it's "finished" according to Michael, and then look at if it's possible to add enough hooks to the compiler for it to be implemented as a plugin. Ideally you'd be able to emit different annotations depending on your use case, for example: lots of other folks have requested automatic JSDoc annotations.
Re:Closure Mode for CoffeeScript by withjive on Friday August 05, 2011 @05:39PM (#2851894)
What's the chance of also getting optional Type Annotations into CoffeScript core as well?

As this would greatly help the closure compiler do optimisations, and since it is opt-in to add the typed parameter and would only produce a javascript comment above said variable.

For example....

foo <: String = "hey"

/* @type {String} */ var foo = "hey"

I don't think this is deviating from CoffeeScript's aim to keep things pure? Is it?

Re:Closure Mode for CoffeeScript by jashkenas on Friday August 05, 2011 @06:24PM (#2852045)
It is deviating pretty far from compiling to readable, standard JS, but again ... as a fork or a plugin, I'm all for it. The reason why the entire CoffeeScript source is annotated is to make variants like this easier to accomplish.

That said, statically marking your variables with "types" (where types are incredibly weak and limited in JavaScript) isn't going to be of much use to you, performance-wise. Modern engines like V8 already unbox local variables where possible, and do "hidden class" analysis to give a "type" even to regular unstructured JS objects.

Re:Closure Mode for CoffeeScript by withjive on Friday August 05, 2011 @06:38PM (#2852091)
What I'm after for typed annotations is integration with the closure compiler to give me static checking, so in large codebases I get that type safety, even in javascript.

Thanks anyways though

Re:Closure Mode for CoffeeScript by noonat on Saturday August 06, 2011 @10:00AM (#2853844)
A standard way of doing type annotations would also make it possible to generate AS3 code with CoffeeScript.
Re:Closure Mode for CoffeeScript by fortes on Friday August 05, 2011 @05:33PM (#2851873)
Love it. Could also imagine an ES5 mode, etc.
Re:Closure Mode for CoffeeScript by bolinfest on Friday August 05, 2011 @07:28PM (#2852231)
When I met Jeremy at JSConf (this was at the end, during the super-loud party), I asked whether such a patch would ever be accepted, and he said, "no, probably not." Obviously that didn't stop me and I'm glad to hear that it would be considered once it has matured :)

If it were to happen, then yes, it should certainly be an option, though to clarify, you can use the Library without the Compiler, and the way things are written now, the only file from the Closure Library that your generated code would depend upon is the bootstrapping base.js file. (Though it may also depend on array.js down the road -- see the section "Leveraging More Closure Library Built-ins" on http://bolinfest.com/coffee/features.html.)

But I think it's completely fair to wait until it's "finished" before trying to upstream it, as Jeremy suggests. It will likely take a bit of refactoring for the CoffeeScript code to support "plugins" such as these. As you can see, I'm just spraying "if o.google" statements in https://github.com/bolinfest/coffee-script/blob/master/src/n... to get things done right now, which would not be acceptable to upstream in its current form.

Re:Closure Mode for CoffeeScript by boucher on Friday August 05, 2011 @09:33PM (#2852576)
I think it's great you're working on this. I'd love to see a version of CoffeeScript that lets you output code compatible with Closure compiler's strict mode, considering the significant reduction in size you can achieve.

I've been writing some of my latest stuff in strict mode style and it's kind of a burden to keep track of what you can and cannot do (plus the code is fairly ugly). I'd love to be able to just write in CoffeeScript and know I'd be compatible. (Personally less interested in using Closure as a library, but still cool that the work is being done).