Live data from Hacker News

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

jashkenas.github.com

21–30 of 67 posts

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

#21
post #14

Heh... Might want to choose a file extension other than ".cs".

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.

I think the biggest issue is that it makes it hard for programming environments to pick the right syntax coloring. There may also be problems selecting the MIME type when serving the file.

So if you have to use a conflicting file extension, you probably want to use one that isn't already associated with a major programming language or web file type.

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

#22
post #19

Earlier quoted context omitted.

Yeah, the periods to end block scope are the part of the syntax I'm the least happy with. I couldn't think of anything nicer without resorting to significant whitespace (which I'd like to avoid). 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…

Out of curiosity, what makes you want to avoid significant whitespace? I think it solves the issue quite nicely. For what it's worth, I used to think SW was completely absurd. Then I spent a few years actually writing Python and have no desire to ever go back.

Python's requirement of indentation is somewhat limiting in terms of what the language can do. For instance, that's partly the reason why Python doesn't allow more than a single expression in a lambda.

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

#23
This is nice. There are too many gotchas to remember in JavaScript; better to let a liberal compiler translate something nice into the "machine code" that works in all browsers.

(Personally, I always write:

   something = {
       foo: "bar",
       bar: "baz",
   }
which works in Firefox, but not IE. A compiler would not be upset when it omits that extra trailing comma. Of course, you can always write:

    something = { foo: "bar"
                , bar: "baz"
                }
But let's face it, that is only not ugly in Haskell.)

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

#24
post #20

JavaScript has always had a gorgeous object model hidden within Java-esque syntax. CoffeeScript is an attempt to expose the good parts of JavaScript through syntax that favors expressions over statements, cuts down on punctuation noise, and provides pretty function literals. This CoffeeScript: square: x => x * x. Compiles into this JavaScript: var square = function(x) { return x * x; }; If anyone has specific ideas a…

Alright, this is bugging me. Why are you using colons for assignment?

I am not the author, but I assume because it's nice-looking, and JavaScript already uses it for assignment (inconsistently). Consider:

   var foo = 42;

   { foo: 42 }
Why make the two concepts different?

Also, it's "binding", not assignment.

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

#25
post #19

Earlier quoted context omitted.

Yeah, the periods to end block scope are the part of the syntax I'm the least happy with. I couldn't think of anything nicer without resorting to significant whitespace (which I'd like to avoid). 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…

Out of curiosity, what makes you want to avoid significant whitespace? I think it solves the issue quite nicely. For what it's worth, I used to think SW was completely absurd. Then I spent a few years actually writing Python and have no desire to ever go back.

I like to have the flexibility to indent in whatever style the code calls for. That said, looking over the Python docs again, their implementation of significant whitespace is a lot more flexible than I remembered. I didn't realize you could do one-line method definitions, and that the whitespace only kicks in when you write a multi-line block.

Here's a question for you. In Python, if you have a couple of nested lambdas with multiline bodies, getting passed into each other as arguments, do you have to write the closing parenthesis on the correctly-indented line on the other side, or can it be tucked against the inner lambda?

In a hypothetical significant-whitespace CoffeeScript, I'm thinking of this:

    elements.each(el =>
      el.click(event =>
        el.show()))
Versus this:

    elements.each(el =>
      el.click(event =>
        el.show()
      )
    )
Is the second form required to make Python-style whitespace work?

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

#26
post #7

Beautiful! (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 (…

Yeah, the periods to end block scope are the part of the syntax I'm the least happy with. I couldn't think of anything nicer without resorting to significant whitespace (which I'd like to avoid). 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…

Its quite pleasing; well done!

My take on the blocks is that significant whitespace seems to be a natural expression of blocks for your language and fits quite nicely with the aesthetics of the other forms. (The terminal ... choo choo train is not a winning idea.)

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

#27
post #20

Earlier quoted context omitted.

Alright, this is bugging me. Why are you using colons for assignment?

I am not the author, but I assume because it's nice-looking, and JavaScript already uses it for assignment (inconsistently). Consider: var foo = 42; { foo: 42 } Why make the two concepts different? Also, it's "binding", not assignment.

    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 "this" context object)

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

#28
post #20

Earlier quoted context omitted.

Alright, this is bugging me. Why are you using colons for assignment?

I am not the author, but I assume because it's nice-looking, and JavaScript already uses it for assignment (inconsistently). Consider: var foo = 42; { foo: 42 } Why make the two concepts different? Also, it's "binding", not assignment.

Erm... no, it's assignment. At least according to the documentation: http://jashkenas.github.com/coffee-script/#assignment

At any rate, I was just curious. To me,

    x = 1
looks more intuitive than:

    x: 1
But that's just my personal preference.

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

#29
post #19

Earlier quoted context omitted.

Out of curiosity, what makes you want to avoid significant whitespace? I think it solves the issue quite nicely. For what it's worth, I used to think SW was completely absurd. Then I spent a few years actually writing Python and have no desire to ever go back.

I like to have the flexibility to indent in whatever style the code calls for. That said, looking over the Python docs again, their implementation of significant whitespace is a lot more flexible than I remembered. I didn't realize you could do one-line method definitions, and that the whitespace only kicks in when you write a multi-line block. Here's a question for you. In Python, if you have a couple of nested lamb…

No.

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

#30
post #22
post #19

Earlier quoted context omitted.

Out of curiosity, what makes you want to avoid significant whitespace? I think it solves the issue quite nicely. For what it's worth, I used to think SW was completely absurd. Then I spent a few years actually writing Python and have no desire to ever go back.

Python's requirement of indentation is somewhat limiting in terms of what the language can do. For instance, that's partly the reason why Python doesn't allow more than a single expression in a lambda.

It doesn't? Is there some kind of documentation about it we can look at?
Post reply on HN