from Hacker News

Replace CoffeeScript with ES6

by Croaky on 1/30/15, 1:54 AM with 168 comments

  • by mrinterweb on 1/30/15, 3:26 AM

    The 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.

  • by jashkenas on 1/30/15, 3:21 PM

    Folks, 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

    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.

  • by addisonj on 1/30/15, 2:49 AM

    I 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.

  • by picardo on 1/30/15, 3:47 PM

    CoffeeScript 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

    [1] http://stackoverflow.com/questions/15223430/why-is-coffeescr...

  • by zerker2000 on 1/30/15, 5:51 AM

      it 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.
  • by abecedarius on 1/30/15, 3:04 AM

    ES6 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.
  • by albertoleal on 1/30/15, 3:02 AM

    Should be retitled 'Replace CoffeeScript with 6to5'.

    You can start using transforms that provide features other than ES6: https://6to5.org/docs/usage/transformers/

  • by sgslo on 1/30/15, 2:42 AM

    Yes 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.
  • by slimetree on 1/30/15, 7:22 AM

    What 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.

  • by sebastianmck on 1/30/15, 3:36 AM

    There's also decaffeinate[1] that converts CoffeeScript to ES6.

    1. https://github.com/eventualbuddha/decaffeinate

  • by meowface on 1/30/15, 2:41 AM

    Why not both? This makes a good argument for ES6, but CoffeeScript's fundamental changes to syntax are just preferred by some.
  • by lucaspiller on 1/30/15, 4:24 AM

    I 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.
  • by pjwal on 1/30/15, 12:41 PM

    The "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.

  • by msutherl on 1/30/15, 5:36 AM

    Is there a preprocessor/transpiler that lets you write vanilla ES6 but just without brackets, semi-colons, etc. like CoffeeScript?
  • by mikeryan on 1/30/15, 2:56 AM

    Note 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/Refe...

  • by risent on 1/30/15, 6:28 AM

    ES6 make JavaScript more powerful, but CoffeeScript is really elegant in a Python developer's scope.
  • by kin on 1/30/15, 4:39 PM

    I 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.

  • by shittyanalogy on 1/30/15, 4:33 AM

    Mmmm 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.

  • by someguy1233 on 1/31/15, 11:40 AM

    I'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.

  • by nothrabannosir on 1/30/15, 5:41 AM

    If 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).
  • by jongraehl on 1/31/15, 5:20 PM

    Braces 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'.

  • by rtfeldman on 1/30/15, 6:05 PM

    The 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.

  • by mhd on 1/30/15, 9:17 AM

    First 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?

  • by amelius on 1/30/15, 11:27 AM

    Minimizing 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.

  • by mkolodny on 1/30/15, 3:04 AM

    For those using browserify, you can use es6ify to compile ES6 to ES5 on the fly.

    https://github.com/thlorenz/es6ify

  • by ziahamza on 1/30/15, 7:51 AM

    The 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.
  • by tiglionabbit on 1/30/15, 9:09 AM

    CoffeeScript compiles down to ES3, which means it's compatible with Old IE. The ES6 compilers can only compile down to ES5.
  • by quadratini on 1/30/15, 4:33 AM

    Coffeescript is pretty damn ugly. For god sakes can people please use parenthesis when calling functions with arguments?
  • by scotty79 on 1/30/15, 12:52 PM

    There 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.

  • by gankgu on 1/30/15, 3:02 AM

    Good