9 ms·
CoffeeScript 1.7.0
- jashkenas 13y agoThere's also a nice writeup of some of the more user-visible changes available here: https://gist.github.com/aseemk/8637896 https://gist.github.com/aseemk/8637896
- jashkenas 13y ago(couldn't edit parent, so) Top 3 things tl;dr Paren-free chaining (think jQuery or d3): bar = svg.append 'rect' .attr 'fill', 'papayawhip' .attr 'width', width .attr 'height', 0 .attr 'y', height .attr 'data-hover', data.slug Ellipsis for soaking up matching parameters, even if you don't want to name a variable: [first, ..., last] = arrayOfStuff lastArgumentFn = (..., last) -> last ... and generally improved source maps.
- xixixao 13y agoAnd together with source maps significantly improved error reporting. I think that might be important for some people who struggled with CS's syntax.
- kaonashi 13y agoNice… I had been using '__', but it seems like this will allow you to use it multiple times in a parameter list.
- couchand 13y agoIt's even cooler than throwaway names [0]. You can index from the back: arr = [1, 2, 3] [..., two, three] = arr or look for node-style callbacks... myFun = (..., cb) -> cb() But you can't use it multiple times. That would allow for ambiguous syntax: # disallowed [..., whatAmI, ...] = [1, 2, 3, 4] [0] https://gist.github.com/aseemk/8637896#expansion-in-array-destructuring https://gist.github.com/aseemk/8637896#expansion-in-array-de...
- latchkey 13y ago...it also seems to compile a bit faster. for my project... 1.6.3 real 0m2.287s 1.7.0 real 0m1.655s
- elwell 13y agoOh goodie! My critical bugfix is now in the CoffeeScript stable: https://github.com/jashkenas/coffee-script/pull/3193 https://github.com/jashkenas/coffee-script/pull/3193
- neals 13y agoIs coffeescript still hip? I used to read a lot about it on here, maybe a year or two. Where is it at? Mainstream?
- vezzy-fnord 13y agoConsidering companies like Dropbox and GitHub use it (even outright recommend it), I'd say it's pretty mainstream.
- xixixao 13y agoAs well as Palantir.
- tlrobinson 13y agoAnd Stripe (https://stripe.com/blog/stripejs-and-jsonp https://stripe.com/blog/stripejs-and-jsonp)
- cicloid 13y agoI think they are moving to TypeScript
- L8D 13y agoThere has been a development of hate towards CoffeeScript in most JavaScript communities. CoffeeScript seems to be very popular in the non-JS communities that need to write JavaScript, like in the Ruby and Python web development communities. CoffeeScript was designed for non-JS coders to feel a lot more comfortable writing JS.
- neals 13y agoI had no idea it was like that. I must say I have never used it, I write most of my JS with HAXE. But hating it seems silly.
- untog 13y agoCoffeeScript was designed for non-JS coders to feel a lot more comfortable writing JS. I'm not so sure about that. I use it as an experienced JS developer because it makes a lot of needlessly complex JS operations simpler. Most of those are features in ES6, so it may well go out of vogue then - I've played around a little and may well end up returning to JavaScript at that point.
- tieTYT 13y ago> Leading . now closes all open calls, allowing for simpler chaining syntax. I feel like this is an important improvement, but I don't really understand what it means. Can someone elaborate on what this means and how it works? How did things used to be different?
- xixixao 13y agoresult = range 1, 3 .concat range 4, 6 .map (x) -> x * x .filter (x) -> x % 2 is 0 For example, the leading `.map` closes the open call to `range` and the open call to `concat`. Before 1.7.0, `.map` would be called on the number 6.
- bobbyi_settv 13y agoIt would have been nice if their code example for this feature showed how the code would have looked in the prior version of Coffeescript.
- ndnichols 13y agoIt would look like result = range(1, 3).concat(range 4, 6).map((x) -> x * x).filter (x) -> x % 2 is 0 or result = range 1, 3 result = result.concat range 4, 6 result = result.map (x) -> x * x result = result.filter (x) -> x % 2 is 0
- xixixao 13y ago$('body') .click (e) -> $('.box') .fadeIn('fast') .addClass '.active' .css 'background', 'white' If I omit as many parentheses as possible. Also for the other example: result = range(1, 3) .concat(range 4, 6) .map((x) -> x * x) .filter (x) -> x % 2 is 0
- rayshan 13y agoInstead of this: $ 'body' .click (e) -> $ '.box' .fadeIn 'fast' .addClass '.active' .css 'marginRight', '10px' You used to have to do this: $('body') .click (e) -> $('.box') .fadeIn('fast') .addClass('.active') .css 'marginRight', '10px' Note the extra ( )s, if not used, the next method call is not recognized as a method call but rather part of the previous call's argument. The last method call did not and does not need to be closed with ( ). This is hugely important for libraries like d3 with super long call chains.
- winslow 13y agoI absolutely love CoffeeScript, with how it structures classes and functions makes sense (plus the python like syntax was a big plus for work). JavaScript seemed to unorganized, unclear, and cluttered for big projects.
- thinkpad20 13y agoI do a fair amount of coffeescript work and every time I see the compiled source I'm so glad that I'm writing in coffeescript. It's not just that it makes certain JS gotchas almost non-issues (almost! there are still several things that can trip you up), it's that it makes clean, concise and correct programming so much easier. There are a lot of things, like curried functions (`f = (a) -> (b) -> result`) or testing for membership in a list (`if foo in [a, b, c]`) which one is much more likely to use in coffeescript than JavaScript because the syntax is so much nicer. Having good syntax doesn't just make it easier to read and write, it promotes good habits and discourages bad ones.
- smrtinsert 13y agoIf I weren't coding ClojureScript now I would at least be in CS. CS is nice, but Clojure is just too strong a language.
- thinkpad20 13y agoI still need to try out ClojureScript. I've heard great things. I prefer the coffeescript syntax, though...
- brokenparser 13y ago// for integer division instead of comments? Are these guys on crack?
- yefim 13y ago# has always been for comments. What are you talking about?
- oblio 13y agoFurthermore, # has been used for comments before //, so he's even "wronger" than he probably thought :)
- jashkenas 13y agoCoffeeScript has always used a single # instead of double // for comments. In previous versions `//` compiled into an empty regular expression – something a little more difficult to express in JavaScript. But also something pretty much useless — hence the willingness to use it as an operator here.
- thedufer 13y agoIts not unheard of. There's another niche language called "Python" that does exactly the same thing. Comments are `#`, as anyone using a unix shell would expect.
- Lazare 13y agoUm, // has never been for comments in coffeescript?
- davidbanham 13y agoUpdated the wrapper.js script we use to run uncompiled coffeescript files in node. It now checks for the existence of .register() and calls it if it's available. https://gist.github.com/davidbanham/8678004 https://gist.github.com/davidbanham/8678004
- moneyrich4 13y agolooks really good, i just wish it compiled to golang.
- yanivt 13y agoWoohoo! Been wanting to chain without parens for a while. Much appreciated change!
- ilaksh 13y agoI love the paren-free chaining but >When requiring CoffeeScript files in Node you must now explicitly register the compiler. This can be done with require 'coffee-script/register' or CoffeeScript.register(). Also for configuration such as Mocha's, use coffee-script/register. Since I have not been specifying my CoffeeScript version, I have a feeling this update is going to break a lot of my Node.js code. Am I right?
- xixixao 13y agoIf you are running your code via 'coffee' or if you are compiling your code to JS this won't affect you.
- elwell 13y agoLet's all take a moment to reflect on the elegance of the grammar.coffee file [0]. Notice how the function named 'o' provides simplicity as it plays well paren-less function calls. [0] - https://github.com/jashkenas/coffee-script/blob/master/src/grammar.coffee#L70 https://github.com/jashkenas/coffee-script/blob/master/src/g...
- aroman 13y agoWow that is insanely beautiful to my eyes — thanks for pointing this out! Only thing that might make it better would be a litcoffee version :)
- elwell 13y agoThanks for pointing out litcoffee.
- jewel 13y agoHere is the annotated link for that same file: http://coffeescript.org/documentation/docs/grammar.html http://coffeescript.org/documentation/docs/grammar.html
- acjohnson55 13y agoImpressive!
- ajayjain 13y agoWhat does %% do? The documentation says: a %% b is the same as (a % b + b) % b, but what is the difference between "true mathematical modulo" and the standard modulo?
- paradoja 13y agoI guess: -2 % 6 = -2, but -2 %% 6 = 4.
- btmills 13y agoYep. I think the name for it is true or Euclidean modulo. Here's the pull request that introduced it and two other new operators: https://github.com/jashkenas/coffee-script/pull/2887 https://github.com/jashkenas/coffee-script/pull/2887
- thedufer 13y agoThe "standard modulo" is actually a remainder operator, and is a js-specific thing. Most languages implement the "true mathematical modulo", aka modulo. One reason this is useful is if you want an array to wrap around. With modulo, you just index on `index % length` and all is well. But with remainder, this will only do what you want for `index >= 0`, because it can give negative outputs, given negative inputs.
- Kerrick 13y agoThis should make consuming promises a lot more readable! api.get 'comments/1' .then transformComment .then (comment) -> appendwithEvents comment, 'click' cacheComment comment .fail console.error
- drinchev 13y agoThe greatest thing that I found in 1.7.0 is a step towards JSDoc with better comment support : ###* # Test ### will be compiled to /** * Test */ And until now /** # Test */