Live data from Hacker News

IcedCoffeeScript

maxtaco.github.com

41–50 of 63 posts

Re: IcedCoffeeScript

#41
It's fantastic to see so much enthusiasm and innovation happening around JavaScript.

While I'd love to see some of these features find their way back into the core language (or native support for coffeescript in node or browsers) it's fair to say that's a long time off if it's ever going to happen.

In the meantime, I'm getting to massively clean up the logic and syntax of my apps. Huge thanks to everyone working on this!

Re: IcedCoffeeScript

#43

The way that this manages to transform those examples makes me think that it would make all kinds of other things more palatable than the vanilla coffee script. I've written chains of callbacks in plain JS that this would make so much nicer to work with.

Can't agree more. There is no other language in the world that needs this as badly as JS does.

- I am hoping that this would be merged back if it could be somehow concluded that there isn't a much cleaner way to achieve the same result. Even if the resulting JS isn't as clean as what CS produces now. The ICS approach looks safe; they could be assured by similar approaches in more mainstream languages, most prominently C# (and F#) which have much bigger teams attacking the same problems.

If the prospect of this getting merged back looks bleak, I might consider switching ICS once I am convinced there aren't any other breaking issues.

Re: IcedCoffeeScript

#44
post #40
post #39

Earlier quoted context omitted.

I tried to formulate very differently so you can see that as another point of view. Sorry for the lack of formality. defer is a function which returns another function. When that returned function is called, we get out of the await block. So, to take the same example: await for k,i in keywords search k, defer out[i] Here, defer(out[i]) returns a function. We pass this function to search. Search is like this: search =…

Thank you for your thoughtful answer, it's clarified some issues. I'm afraid it also raises more questions for me (I probably need to go study CoffeeScript some more). BTW, the text I added is actually from the first example - the simplest: await $.getJSON url, defer json Is the following right? Syntactically, "defer json" is an argument to the function "$.getJSON". So you could write it like this: await $.getJSON( u…

Note that I haven't tested ICS so it's only based on my understanding of the examples/docs.

"Is the following right? Syntactically, "defer json" is an argument to the function "$.getJSON". So you could write it like this: await $.getJSON( url, defer(json) )"

Yes, exactly.

"'m guessing it's some convenient compiler magic that ICS does"

Yes, exactly. When you say "defer(x)", it basically returns a callback like this:

  function(result) {
    *x = result;
    Code to terminate the await block*
 }
"One last thing: the description talks about "deferrals" begin "fulfilled", but it doesn't say how they are created. Now, I think they are created by calling defer."

Yeah, defer returns a callback and when you call it, it "fulfills" the await, i.e. you tell await that you're done with that async block.

Re: IcedCoffeeScript

#45

This fork brings some up deep issues, perhaps intractable, around about the development of syntax-y languages. Useful source transformations require marginalized forks of the compiler and all the development burden and risks that entails. In some sense CoffeeScript inherits the actual problem with JavaScript - a select few determine the introduction of language features. Perhaps these language features are best shipp…

> the actual problem with JavaScript - a select few determine the introduction of language features. What language exists in which this is not the case? Language by committee sounds terrible.

Haskell was designed by committee.

Re: IcedCoffeeScript

#46

It's fantastic to see so much enthusiasm and innovation happening around JavaScript. While I'd love to see some of these features find their way back into the core language (or native support for coffeescript in node or browsers) it's fair to say that's a long time off if it's ever going to happen. In the meantime, I'm getting to massively clean up the logic and syntax of my apps. Huge thanks to everyone working on t…

Harmony will include generators, which are basically coroutines.

Re: IcedCoffeeScript

#47
post #44
post #40

Earlier quoted context omitted.

Thank you for your thoughtful answer, it's clarified some issues. I'm afraid it also raises more questions for me (I probably need to go study CoffeeScript some more). BTW, the text I added is actually from the first example - the simplest: await $.getJSON url, defer json Is the following right? Syntactically, "defer json" is an argument to the function "$.getJSON". So you could write it like this: await $.getJSON( u…

Note that I haven't tested ICS so it's only based on my understanding of the examples/docs. "Is the following right? Syntactically, "defer json" is an argument to the function "$.getJSON". So you could write it like this: await $.getJSON( url, defer(json) )" Yes, exactly. "'m guessing it's some convenient compiler magic that ICS does" Yes, exactly. When you say "defer(x)", it basically returns a callback like this: f…

Thanks a second time, I'm getting there! I realized one can look at the transformed javascript output, to see just what it does. The setting of the variable in the defer becomes:

  $.getJSON(url, __iced_deferrals.defer({
      assign_fn: (function() {
        return function() {
          return json = arguments[0];
        };
      })(),
      lineno: 6
    }));
Presumably, when the function that __iced_deferrals.defer returns is called by the code in .getJSON that delivers the result, it will set arguments[0] to that result, and then call the assign_fn above. This will set json to that result.

Also, I realize that it doesn't set json to the returned value of $.getJSON, as $.getJSON doesn't return anything - it uses a callback to deliver its result. It seems that ICS always works this way - which I guess implies that the use-case it's for always uses callbacks...

BTW: I'm not sure why the above has a function which is then called immediately. Maybe a coffeescript thing, for separating namespaces? I assume the lineno: 6 is for debugging - I recall some debate against this. Good to see it got in.

Re: IcedCoffeeScript

#48

This fork brings some up deep issues, perhaps intractable, around about the development of syntax-y languages. Useful source transformations require marginalized forks of the compiler and all the development burden and risks that entails. In some sense CoffeeScript inherits the actual problem with JavaScript - a select few determine the introduction of language features. Perhaps these language features are best shipp…

Regarding development burden, if ICS is implemented as additions to the language, then it can get all updates to the rest of CoffeeScript from "underneath" - the only proviso is that CoffeeScript syntax doesn't change incompatibly with it. And as ICS can be seen as a simple macro (plus libraries it uses), I would guess it is implemented this way (simple source transform on top of CoffeeScript, not hacking at the Jison grammar). This is one way around the issue you raise.

Regarding the whether it's part of the language or a library as a distribution issue, it depends on what benefits users. For syntax, there's some benefit in uniformity (other developers can read it). I'm seeing ICS as a suggestion of a new feature in CoffeeScript. If it's really good (meets a need; bugs and design mistakes are fixable and fixed; it doesn't break other things), it could be back-integrated into CoffeeScript proper. Whether to do so can be better decided once data exists. :-)

It's a great forking model for exploring new syntax, IMHO.

EDIT but it breaks the CoffeeScript philosophy of readable JavaScript, and (eg) addes debug line numbers in to the source code (see "load" on the sample code). Also, other examples and more details on ICS here https://github.com/maxtaco/coffee-script/blob/iced/iced.md

Re: IcedCoffeeScript

#49
Nice work, I love the syntax. Was a bit disappointed at the verbosity of the compiled js though. Wondering if the same thing could be achieved without the secret functions, classes & variables? (Deferrals, findDeferral, __iced*...)

I think I can imagine a more direct translation of await & defer, though of course I haven't actually tried to implement it (yet).

Re: IcedCoffeeScript

#50

Why didn't the "iced" feature just get added to CoffeeScript? Why have two separate packages?

This is a fork of the language, not an official feature. It’s as if you wrote your own version of JavaScript that trampolines function calls and performs tail-call optimization. You still need to go through the social process to get your ideas into the main “trunk.” Selling people on adopting your fork might be one way to get everyone excited about the idea. That being said, right up front he explains the two reasons…

> code written in IcedCoffeeScript no longer compiles into more-or-less recognizable JavaScript

So this is a more fundamental fork than first appears... And it explains why it includes debugging information (loading up the code examples reveals artifacts like lineno: 6 in the output JavaScript).

I recall a debate about debug info, turning on the values you note. Can't find it right now. (though, apparently extra-linguistic Source Maps are being introduced into browsers http://news.ycombinator.com/item?id=2862629)

Personally, I think "clean JavaScript" is the right adoption strategy, for now, in a JavaScript-dominated world. When CoffeeScript has native browser support, that value can be dropped (it might not happen: MS supports VB, Google supports Dart... even if Mozilla supports CS, the others mightn't).

Finally, I don't think the resulting JavaScript is that hard to understand - you can easily see the correspondences with the source. However, it's the thin-edge of the wedge. What changes will be added next?

Post reply on HN