3 ms·
> Have you considered porting Ruby directly to JavaScript? No. It's been attempted before, and it doesn't turn out to be terribly useful in the end, because of
by jashkenas 13y ago
> Have you considered porting Ruby directly to JavaScript?
No. It's been attempted before, and it doesn't turn out to be terribly useful in the end, because of the vast semantic mismatch between the two languages. See: https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS#ruby https://github.com/jashkenas/coffee-script/wiki/List-of-lang...
> I've never gotten over the usage of "->" or "=>" to signify a function.
Give it a try, perhaps. It's critical not to use "def" and "do" when your functions are first-class values that can be passed as arguments, or assigned to variables. It's for this reason that Ruby 1.9 has a new lambda syntax that looks a great deal similar to CoffeeScript's. For example:
request(url, def callback(response) do
...
end)
... that kinda thing is no good.
The reason it's an arrow is because in any decent function, the input determines the output, eg. input points to output. And therefore, the CoffeeScript syntax: (input) -> output
- ChrisAntaki 13y ago>> it doesn't turn out to be terribly useful in the end True, I'd chose CoffeeScript over Opal. >> Give it a try, perhaps. Oh, I dig it, especially the fat arrow. >> It's critical not to use "def" and "do" when your functions are first-class values that can be passed as arguments, or assigned to variables. Still, I find "def" to be more `readable` than arrow symbols. I'm not sure how JavaScript's first class status for functions would deter a keyword containing letters. Considering JavaScript itself uses function as its. >> The reason it's an arrow is because in any decent function, the input determines the output, eg. input points to output. And therefore, the CoffeeScript syntax: (input) -> output That definitely makes logical sense. Still, I feel the readability might be increased by using words, which the mind is more attuned to quickly applying meaning to. Edit: Great job, on CoffeeScript, regardless!
- WickyNilliams 13y agoAlso worth pointing out that the fat arrow lambda expression is coming in ES6 [1] so you will see it in vanilla JS soon! [1] http://www.nczonline.net/blog/2013/09/10/understanding-ecmascript-6-arrow-functions/ http://www.nczonline.net/blog/2013/09/10/understanding-ecmas...