9 ms·
Replace CoffeeScript with ES6
- meowface 12y agoWhy not both? This makes a good argument for ES6, but CoffeeScript's fundamental changes to syntax are just preferred by some.
- recursive 12y agoBecause one day ES6 will run in browsers without a build step.
- spellboots 12y agoIs that a major concern? In practice, it's unlikely any serious use of ES6 will run in a browser without a build step due to concatenation, minification etc
- matthewmacleod 12y agoI'm not sure that's a convincing argument – you will in almost every conceivable case have a build pipeline in place anyway, so there's not really a cost there.
- Touche 12y agoI don't set up a "build pipeline" until I'm sure the app is going to deployed to a production environment. Why would I set up a build for what is essentially a fiddle, or if I'm just experimenting? The now-common workflow where people write build scripts at the start of a new project is just bizarre to me.
- mistercow 12y agoYou're partially right, but every build step has a cost when you're working on a large project.
- akst 12y agoIn my experience all non-trivial frontend project I've worked on have ended up with some kind of build step (minification, linting, concating, ect), with or without a compile2JS language. This isn't an issue for node projects as you can simply `require` the `coffee-script/register` module and node handles coffee scripts for you via normal `requires`.
- Touche 12y agoYou don't actually need a build step for either in development. Any client-side loader can compile your CS code on the fly.
- mambodog 12y agoYeah but then we'll just be compiling our ES8 code with 8to6.
- itistoday2 12y agoSome reasons why I will stick with CS: * Optional braces and parenthesis. Results in visually cleaner and more compact code, especially when dealing with large objects. * Requiring backticks to do string interpolation seems like an ugly hack. * CS uses dots to slice and splice ranges: host?.split(".")[-1..][0] == "dns" BTW, notice in the example above two additional CS features that don't exist in ES6: * The existential operator `?` soaks up null/undefined references. * `==` is compiled to `===` * Expressions always return a value in CS, just like in Lisp, so no need to explicitly `return` * Block strings and regular expressions. And more: http://coffeescript.org/ http://coffeescript.org/ Plus, CS just seems like it's always a step ahead of JS. In using it, you can code in a more intelligently designed language that enforces best-practices better than JS does. Doing so supports diversity, innovations (after all, many of these ES6 features are obviously inspired by CS). Why abandon such a wonderful language when it still has so much to offer, and at the same time seems to be driving innovation in JavaScript itself?
- endemic 12y agoI looked at 6to5 and started re-writing a few files of CoffeeScript in ES6. First impression was not great. I'd forgotten how many curly braces are required in JS. ES6's fat arrow is just not as nice as CoffeeScript's (required parentheses, no option for thin arrow). I'll no doubt try it out again soon, but I'm not a convert yet.
- nawitus 12y agoES6 fat arrow syntax doesn't require parentheses if there is only one function parameter. If there are more, parentheses make the code more readable in my opinion.
- stn 12y ago'is' is also very cool: makes it harder to write '=' instead of '=='
- agumonkey 12y agoI wonder if CS will evolve further now that ES6 is about to land.
- sgslo 12y agoYes and no. Although we get some fantastic features, one of the most critical- the ability to neglect parens and curly braces- is lost in es6. I'm working on an es6 project right now and still prefer coffeescript.
- recursive 12y agoFor functions of single arguments, you parameter list parens are optional. But it's not an objective fact that coffeescript's syntax is better. I prefer ES6. And even if you prefer coffeescript, it seems strange to claim that the most critical feature is purely aesthetic.
- briandear 12y agoAssuming it's all ultimately JS, the aesthetic side is a big deal. It results in an easier time understanding and being able to debug the code, which is a huge, perhaps underestimated win.
- stephen_g 12y agoThat's interesting - personally I've always really disliked that about Coffeescript. It may just be because of how familair I am with C-family languages, but I always liked the default Javascript style far better. So from my perspective ES6 is the best of both worlds - the better syntax of Javascript and the features that Coffeescript gave you.
- pekk 12y agoIt sounds like it would be relatively easy to write a preprocessor to do only this
- smrtinsert 12y agoAgreed that it's way nicer.
- addisonj 12y agoI give credit to CoffeeScript with really helping to push the ES specs forward and think it helped introduce more people to JS and grow the ecosystem. Heck, I used it for a year, liked it, and had it change some of my approaches to writing JS. That said, I hope it slowly fades into the background as more people go back to vanilla ES6 or go with something more powerful such as TypeScript (or Flux). With the progress around es6 and es7, gradual typing, macros, and other tooling around the language, I think CoffeeScript risks becoming a drag on getting people to learn modern JS and instead sticking with a language that has a lot of ambiguous constructions and fewer and fewer advantages over JS.
- ffn 12y agoIt's also possible folks will continue forking and improving CoffeeScript so that it keeps up with future releases of vanilla js (which is actually what I hope will continue to happen). Folks like me who come from a Ruby / Python background really don't like brackets and declaring variables, so things like Coffeescript, LiveScript, CoCo, etc. are wonderful tools even despite their occasional moments of weakness. That being said, you're absolutely right, folks who write in Coffee should also absolutely eventually learn all the tips and tricks behind vanilla js also if they don't want to be bogged down.
- smrtinsert 12y agoI almost feel like the coffeescript variants are where the action is.
- mikeryan 12y agoNote that self = this is kind of a legacy hack for binding 'this'. ES5 has Function.bind https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- cozuya 12y agoIf you want to call something that increases performance by 50% a hack, feel free, but I'm going to use that hack until that's not the case.
- nkohari 12y agoDo you have a source? I don't understand how a closure over a single variable (this), instead of reassigning the value of the variable in a specific scope, would result in a 50% improvement in performance. Also -- the phrase "50% improvement in performance" itself is kind of dubious, no?
- peter_l_downs 12y agoIt can also be nice when you're writing instance methods on a prototype. for instance: var Person = function(name) { var self = this; self.name = name }; Person.prototype = new function() { var prototype = this; prototype.sayHello = function() { var self = this; return "Hello\n\n-- " + self.name; }; }; var me = new Person('Peter'); console.log(me.sayHello()); Obviously that's a pretty contrived example but it illustrates the idea. It makes it really clear exactly what "this" means at different points in your code. As a bonus, if I had to reference the current context inside of a prototype method, "this" is now available.
- gankgu 12y agoGood
- albertoleal 12y agoShould be retitled 'Replace CoffeeScript with 6to5'. You can start using transforms that provide features other than ES6: https://6to5.org/docs/usage/transformers/ https://6to5.org/docs/usage/transformers/
- mkolodny 12y agoFor those using browserify, you can use es6ify to compile ES6 to ES5 on the fly. https://github.com/thlorenz/es6ify https://github.com/thlorenz/es6ify
- sebastianmck 12y agoAlternatively there's 6to5ify[1] 1. https://github.com/6to5/6to5ify https://github.com/6to5/6to5ify
- abecedarius 12y agoES6 has 'let', while CoffeeScript has an '=' that might be local binding and might be nonlocal assignment, depending on what's in scope. I wanted to like CS, but I don't want to live with that one decision.
- iopq 12y agoSame here, after I learned about "lexical scoping" in college I couldn't imagine using a language without it.
- batiste 12y agoThe scoping issues with CoffeeScript is what triggered me creating this little language: http://batiste.info/CokeScript/ http://batiste.info/CokeScript/ At this point it still a bit of a joke, but if I have more time to work on it I could take to a usable state.
- mrinterweb 12y agoThe reason that I like CoffeeScript is that it removes, what I consider, the unnecessary boilerplate of JavaScript and replaces it with a shorthand equivalent and good conventions. I feel that CoffeeScript is better at representing the intent of JS than JS. I can visually sift through CoffeeScript and understand the code much quicker than normal JavaScript, which in my opinion leads to more maintainable code. I'm not certain what is appealing about reading and writing more code for the same result. Many people don't like that CS needs to be compiled. I don't see this as an issue since pretty much every application I work on these days is concatenated and uglified. So adding a JS compiler is already part of most JS application's build process. 6to5 is being compiled to ES5 anyway. Also, if you include in your build pipeline a source mapper, debugging is not a problem.
- qwer 12y agoMy biggest problem is definitely the source maps. It took me forever to get them to "work" and while the stack traces are mostly correct, they're often off by a line number or two. This makes debugging ridiculously hard when the line numbers are just "close". I know this might not sound like a big deal in the grand scheme of things, but I also don't think CoffeeScript really improves on js all that much, so the annoyances of source maps are just not worth it to me personally.
- deleted 12y ago[deleted]
- untog 12y agoI'm surprised. I use Browserify (and Coffeeify), which spits out a source map inline at the end of the file, which has not once given me problems.
- jashkenas 12y agoHave you tried them at all recently? If a source map is off by a line, that's a bug that should be reported and fixed pronto.
- serve_yay 12y ago
- sebastianmck 12y agoThere's also decaffeinate[1] that converts CoffeeScript to ES6. 1. https://github.com/eventualbuddha/decaffeinate https://github.com/eventualbuddha/decaffeinate
- lucaspiller 12y agoI wonder if ES6+ is going to become the new HTML5 - all these great features but no hope of proper browser support for years. I had no idea ES7 was also in development, so it seems like browsers are always going to be playing catchup. The comments on an article here the other day said people aren't upgrading tablets as often as phones. I can see a lot of tablets being stuck on ES5, that people don't want to upgrade, as they can still browse the Facebooks and Googles fine.
- mbrubeck 12y agoFirefox and IE11 already natively implement a majority of new ES6 features, and Chrome is getting there: http://kangax.github.io/compat-table/es6/ http://kangax.github.io/compat-table/es6/ The main laggard for now is Safari/WebKit.
- TheHippo 12y agoCurrent stable browser versions: FF 35: 60% Chrome 40: 35% Safari 8/Mobile: 22% IE11: 21%
- mbrubeck 12y agoOops, yeah. I wrote "IE11" but I meant "IE TP". The dev versions of IE/Firefox/Chrome/WebKit are up to 70%/69%/48%/28% respectively.
- pjmlp 12y ago> Chrome is getting there They are busy with that other programming language.
- underwater 12y agoMost of the JavaScript community is already using this, thanks to tools like https://6to5.org/ https://6to5.org/. Developers are excited about new language features not because of browser support, but because it standardizes patterns they were already using (fat arrow functions, Promises, modules, classes, etc.) through CoffeeScript and third-party code.
- quadratini 12y agoCoffeescript is pretty damn ugly. For god sakes can people please use parenthesis when calling functions with arguments?
- briandear 12y agoWhy add unnecessary clutter?
- Gurkenmaster 12y agoLisp programmers would love to disagree
- Guthur 12y agoParenthesis are not unnecessary in Lisp they're an essential delimiter in defining an s-expression's structure (does not need to be parenthesis but some token is required). But for me that one bit of syntax is a lot less that the multitude required for many languages. For something even more syntactically minimal there is Forth.
- batiste 12y agoIt is not unnecessary, it helps the reader building a mental model about what is a function and what is not. I would concede It can be useful to create some DSL or to access an object lazily but the is a price to pay: a more opaque code base
- deleted 12y ago[deleted]
- Guillaume86 12y agoI do it in my coffeescript for function calls. You just need some guidelines and some discipline.
- shittyanalogy 12y agoMmmm without drastic syntax changes? Classes: There is no semicolon after the function name The function keyword is omitted There are no commas after each definition Interpolation: `${1 + 1}` <- why not just # like everyone else? Multi line strings: ` Now we have a 3rd string delimiter` Fat arrow: $("button").on("click", () => { // really? hanging parens? no function keyword? }); Destructuring: var [first, , last] = [1, 2, 3] // thats a var to assign vals inside an array // and just two commas touching to ignore a value The whole post is about drastic syntax changes. The brackets are optional in coffeescript. Besides coffeescript is just a tool.
- ahoge 12y ago> why not just # like everyone else? You mean like CS? '#' actually isn't a very popular choice for this. http://en.wikipedia.org/wiki/String_interpolation http://en.wikipedia.org/wiki/String_interpolation
- pmontra 12y agoCoffeescript's origin is in the Ruby community. The first interpreter was also written in Ruby. Ruby interpolates strings with #{} so that was a logical choice for Coffeescript. The significant spaces thing was ironic given that Python is kind of the biggest competitor of Ruby (×) in the modern scripting languages space. Personally it's the main reason I'm not using CS (or Python or HAML or Slim), transpiling is number 2. (×) kind of because Ruby is probably more successful in web development but less anywhere else.
- tiglionabbit 12y agoI don't understand why significant indentation is a bad thing. It's easier to read indentation than it is to try and match brackets in your head. The only times it bites me is when I accidentally mix spaces and tabs in the same block, which could use a warning.
- 12y ago
- deleted 12y ago[deleted]
- slimetree 12y agoWhat CoffeeScript did was lodge the idea in people's heads that JavaScript can be treated as an assembly language to compile higher-level languages into. I'll bet many programmers' attitudes toward ES6 are: someone will write a compiler for my language, and I'll just use that. It seems better to treat JavaScript as admittedly not being the most powerful language in the world, and to treat the standard as a kind of RFC that only compiler writers have to think about. For most programmers it works to just use CoffeeScript (or Lisp or anything) without worrying about standards, just as JavaScript programmers don't need to worry about how their processor works.
- marcosdumay 12y agoIn fact, maybe Javascript is too powerfull. It would be interesting to get a stack machine emulation in the browser, with an standard set of libraries/tools for native access to the DOM and emulators for most interpreted languages out there. Kind of a Java plugin that runs on web, instead of just tunneling through it.
- deleted 12y ago[deleted]
- msutherl 12y agoIs there a preprocessor/transpiler that lets you write vanilla ES6 but just without brackets, semi-colons, etc. like CoffeeScript?
- mattdesl 12y agoSemicolons are already optional in JS. Automatic semi colon insertion (ASI) has a clear set of rules that are pretty easy to remember. http://mattdesl.svbtle.com/to-semicolon-or-not http://mattdesl.svbtle.com/to-semicolon-or-not
- SomeCallMeTim 12y agoBut ASI is controversial, because of the bugs that can be caused by it. (See "JavaScript, the Good Parts"). I make our devs (myself include) use semicolons with jshint, because I believe it's too easy to screw up.
- Already__Taken 12y agoAfter reading the linked [Isaacs](http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding http://blog.izs.me/post/2353458699/an-open-letter-to-javascr...) post it made me realise a bit more about the language. I don't think I'd agree its easy to screw up. Its as easy as accidentally using global variables.
- mattdesl 12y agojshint warns about these bugs regardless of whether you have ASI flag turned on. Writing semicolon-free code is easy. Just put a preceding semicolon before any lines beginning with: ( [ + -
- nothrabannosir 12y agoIf you're going to use something with JS's syntax, at least take Typescript or Flow for some compile time checks (optional types, function arity, variable names, &c).
- grandalf 12y agoIs there anything like flow for Coffeescript?
- zerker2000 12y agoit solves a lot of the problems that CoffeeScript is trying to solve without drastic syntax changes. I cannot speak to authorial intent, but for me the majority of the problems CoffeeScript(and moreso LiveScript) solves are syntax ones.
- orf 12y agoSame, if I squint a little I'm just writing Python that runs in the browser.
- acjohnson55 12y agoES6 solves many of those same problems that required overly verbose or awkward ES5 syntax. Things like basic this-preserving closures, collection extraction, and so forth. Same problems, similar but less radical solution in ES6 vs. CS
- risent 12y agoES6 make JavaScript more powerful, but CoffeeScript is really elegant in a Python developer's scope.
- ziahamza 12y agoThe biggest reason why I still dont use coffeescript is that most compile javascript tooling doesnt work. I cant use types from TypeScript, or use JSX extentions with coffeescript.
- tiglionabbit 12y agoYou can use coffee-script with JSX. I'm using cjsx-loader with webpack, and there's also a stand-alone cjsx compiler. https://github.com/jsdf/coffee-react https://github.com/jsdf/coffee-react https://github.com/KyleAMathews/cjsx-loader https://github.com/KyleAMathews/cjsx-loader
- deleted 12y ago[deleted]
- tiglionabbit 12y agoCoffeeScript compiles down to ES3, which means it's compatible with Old IE. The ES6 compilers can only compile down to ES5.
- acjohnson55 12y agoThat's not necessarily true. Many of the features can be made ES3 compatible. Of course knowing which ones are exactly isn't always straightforward.
- mhd 12y agoFirst time I heard of sprockets (weird, being German). How many JS build tools are there out now? And is none of it deprecated/abandoned? Other than that, the braces/indentation issue alone will keep people with CS. Can its compiler emit ES6, by the way?
- bshimmin 12y agoSprockets is part of the Rails asset pipeline - it's not used much outside of the Rails world.
- kin 12y agoI had fun with CoffeeScript but my projects definitely had its frustrations. CS allowed me to write some pretty damn ambiguous code. Also when working with external libraries and dependencies, I found myself resorting to trial and error figuring out the correct syntax because nearly all documentation is written in JS and not CS.
- amelius 12y agoMinimizing javascript code using a minimizer currently cannot be done well in a guaranteed way, because the minimizer must make too many assumptions. Therefore, I think javascript is too dynamic for a web-language. Unfortunately, they didn't solve this with ES6.
- pjwal 12y agoThe "all or nothing" with CS has always been a non starter for me. I find it really hard to believe that it is possible for a team of more than 2 or 3 to remain happy with a choice to use it after any extended period of time. If you're out there though, I would love to hear from you! And yes, this can be said for almost any tool choice, but my spidey sense tells me the half life for CS is about that of something like Jira.
- _alastair 12y agomobile.nytimes.com is written in CoffeeScript (frontend and backend) and is maintained by a team of around 8 people. AFAIK all of the developers are fine with it.
- elros 12y agoI don't know what you consider an extended period of time, but I've been writing CoffeeScript full time for 2 years now, and it's been like that at my day job (moviepilot.com) for at least 2 more before I came. Couldn't be happier! Team size varies between 8 to 15 people, roughly.
- scotty79 12y agoThere is very few features of ES6 that are not syntax sugar. Those features will be (or already are) ported to CoffeeScript. And the CoffeeScript sugar is just tastier. ES6 syntax is kind of CoffeeScript for people who hate meaningful indentination and it's quite decent for that purpose.
- M2Ys4U 12y ago> There is very few features of ES6 that are not syntax sugar. (Weak)Map, (Weak)Set, Symbol, Generators, Promises, Modules, Proxies... these aren't sugar.
- scotty79 12y agoSo generator, weak references and proxies. Promises, modules we already had. Native implementation doesn't provide new functionality, just picks winners. I'm really excited by generators and proxies but those are available in latest version of CoffeeScript already.
- jashkenas 12y agoFolks, this was always part of the plan ;) CoffeeScript is a fun little experiment in what's possible when you take JavaScript semantics and try to boil down the user interface to a minimalist surface. But JavaScript will always keep on rolling onwards — and to the extent that future versions of JavaScript take any minor inspiration or reference or overlap with things that CoffeeScript already does, the more the better. For example, see this talk from four (!) years ago: https://www.youtube.com/watch?v=QTj6Q_zV1yg https://www.youtube.com/watch?v=QTj6Q_zV1yg There's more than one way to skin the JavaScript cat. In other news, CoffeeScript 1.9.0 came out yesterday — with support for ES6 generator functions. A-la Python, in CoffeeScript, a generator is simply a function that "yield"s.
- tsax 12y ago^ To those not in the know, the above poster 'jashkenas' is Jeremy Ashkenas, the creator of CoffeeScript and Backbone.js
- ffn 12y agoThank you jashkenas-sama, please keep the good works with coffee (and underscore, backbone, etc.). We Rubyists and Pythonians are all (well, at least I am) eternally grateful to you for having delivered us from the evils of brackets, parenthesis, if !condition, and that thing were we had to firstArg = [].prototype.slice(arguments, 1) in every function where we needed splats.
- danso 12y agoOnly five years ago since the original announcement: https://news.ycombinator.com/item?id=1014080 https://news.ycombinator.com/item?id=1014080 > * 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.
- picardo 12y agoCoffeeScript syntax is better and cleaner than the ES6 syntax. It's a fun language, and I've been using it everyday since it came out. On small projects, it's top-notch. But the future of CoffeeScript is bleak because many software designers are beginning to understand the value of type systems, e.g. TypeScript and Flow, for building maintainable Javascript code bases, and this means CoffeeScript is out of the picture for good because its long term design goal is to remain a minimalistic language, and doesn't intend to support these ideas. There have been attempts[0] to fork it to add a legitimate type system to it so it can scale, but they have faltered. Aside from that, the way CS deals with variable shadowing[1] makes it risky to use in large codebases. So when ES6 syntax is tolerable and stable, I will pack my bags and move over to the ES6 land with great regret. I wish I could stay in CS land for longer, but you have to put away childish things eventually. ------------ [0] https://www.npmjs.com/package/typed-coffee-script https://www.npmjs.com/package/typed-coffee-script [1] http://stackoverflow.com/questions/15223430/why-is-coffeescript-of-the-opinion-that-shadowing-is-a-bad-idea http://stackoverflow.com/questions/15223430/why-is-coffeescr...
- atrilumen 12y agoSpeaking of putting away childish things (like effect-ridden, imperative spaghetti code), PureScript is my new CoffeeScript. http://purescript.org http://purescript.org
- picardo 12y agoI've been looking into that myself, but then I found Elm[0] and stopped looking. :) ------------------- [0] elm-lang.org
- atrilumen 12y agoOh, Elm is cool. I get that. So is Haste[0]. But I think PureScript is a more practical choice for targeting JavaScript. (It generates much smaller, more readable output, for one thing.) I don't promise to have my mind made up, though. I'm still furiously taking in all of this Haskelly stuff, and it looks like a pretty long road ahead. I've been telling people that I feel like I've crawled into a tunnel, and can't back out again. I seem to have no choice but to keep crawling towards that tiny beam of light. I don't know how many times I'd looked at the ML family, and just couldn't appreciate it immediately enough... but somehow I've managed to become completely obsessed, to the extent that anything less really turns my stomach. [0] http://haste-lang.org/ http://haste-lang.org/
- rtfeldman 12y agoThe body of the post doesn't support the title's recommendation. Each section shows how ES6 either has an equivalent feature to CoffeeScript, or almost does; in other words, it is approaching feature parity. To replace one tool with another, you need a compelling reason...and "it's almost at feature parity" is not that.
- someguy1233 12y agoI'm surprised nobody has mentioned TypeScript. I've been using it in one of my projects recently (WebStorm even has a file watcher that works with very little set up on my Macbook). TypeScript is pretty good at giving you a taste of ES6, it brings in a lot of features from ES6, such as the new classes, default arguments, generics, as well as a few of it's own features (interfaces, optional static type checking). They ship it as a node module, so you can just "npm install -g typescript" and it's ready to go. As much as I dislike Microsoft, Typescript is something that seems to work well, and unlike Coffeescript, I can quite happily paste in standard Javascript code (even most ES6 code) and it won't break my source.
- jongraehl 12y agoBraces combined w/ something like clang-format or gofmt are clearly better. Perhaps a really advanced editor (that most people don't use) could offer a similar experience for braceless (sig. indent) languages. Short braceless code typesets beautifully, but you can probably get a similar effect w/ an appropriate 'braces highlight at lower contrast when autoindented as expected'.