CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
jashkenas.github.com
CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
1–10 of 67 posts
Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#2 square: x => x * x.
Compiles into this JavaScript: var square = function(x) {
return x * x;
};
If anyone has specific ideas about aspects of JavaScript that they think could be more convenient or better-looking, I'd love to hear them. Cheers.Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#3Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#4The howto refreshing to read. While I love JS as a language, even written longhand, it feels like you've brought an uncommon elegance to it. The syntax is much simpler and maps more cleanly to how I think. It feels a lot like Ruby.
Granted, most of the JS I work on is in pretty complex applications, so I'd be hesitant to work in anything but the target language itself. But it's a very clean abstraction or concept to begin with. I'd love to see something complex written in CoffeeScript, especially with DOM manipulation or another JS framework involved.
It'd be fun to try writing a DSL or simple compiler sometime. This must have been very interesting to create. Cheers for such detailed examples in the unveiling as well.
Great job, and thanks again!
Edit: Hahaha, thanks for the examples from the Poignant Guide. Pouring out a few drops for _why right now.
Edit 2: Forgot that you wrote underscore.js - thanks for that as well. Crazy to see how simple it is when written in CS.
Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#5Wow, this is a really nice little language. The howto refreshing to read. While I love JS as a language, even written longhand, it feels like you've brought an uncommon elegance to it. The syntax is much simpler and maps more cleanly to how I think. It feels a lot like Ruby. Granted, most of the JS I work on is in pretty complex applications, so I'd be hesitant to work in anything but the target language itself. But…
That said, if you work with Ruby and want to play with compilers, check out CoffeeScript's source. It's got a clean Ruby lexer and Racc parser (examples of which are hard to find in the wild) -- the code generation is a little funky, but I'm hoping to clean that up. The whole shebang is under 1500 LOC, including comments, so it's not too much to wrap your head around.
Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#6My only worry about something like this is the extra step of compiling, though I run a script that compresses via YUI comp. anyway...
Thanks for sharing.
Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#7(I finally made it to the end of the article where you ask about block delimiting...)
I think there are two issues, one being that '........' at the end of a large nested expression is ugly, the other being that it's hard to find the start and end of a block as it stands.
Since you seem to borrow a lot from ruby, why not add {} and/or begin/end as options? I would definitely keep the period syntax around (for short, shallow blocks), rather than replacing it.
"aint"? Cute.
Re: CoffeeScript, a little language that compiles to JavaScript. Happy Holidays, HN
#8Beautiful! (I finally made it to the end of the article where you ask about block delimiting...) I think there are two issues, one being that '........' at the end of a large nested expression is ugly, the other being that it's hard to find the start and end of a block as it stands. Since you seem to borrow a lot from ruby, why not add {} and/or begin/end as options? I would definitely keep the period syntax around (…
I'd rather not add {/}, or begin/end, because it's easy to determine the beginning of the block, it's just closing it that we need a symbol for.
In terms of style, you can certainly indent the period on it's own line if you prefer:
elements.each(el =>
$(el).click(event =>
if el.hidden
el.highlight()
.
.)
.)
But I'd love to hear more suggestions for alternatives.