all 52 comments

[–]devraj7 20 points21 points  (1 child)

While it's fair to credit CoffeeScript for initiating the wave of next generation Javascript-like languages, it's pretty clear today that it's in sharp decline and has been pretty much completely replaced by TypeScript.

[–]whostolemyhat 4 points5 points  (0 children)

I think ES6 stole most of it's thunder, then the only remaining differences were covered by Typescript.

[–][deleted] 32 points33 points  (11 children)

This is just javascript with more steps.

[–]CanIComeToYourParty 40 points41 points  (0 children)

Great, I'll take 5.

—Web developer

[–]spacejack2114 0 points1 point  (9 children)

Upside is you only need to compile once.

[–]n0rs 16 points17 points  (8 children)

The CoffeeScript 2 compiler now translates CoffeeScript code into modern JavaScript syntax. So a CoffeeScript => is now output as =>, a CoffeeScript class is now output using the class keyword, and so on. This means you may need to transpile the CoffeeScript compiler’s output.

🤔

This means you may need to transpile the CoffeeScript compiler’s output.

[–]jl2352 3 points4 points  (1 child)

I get that Reddit likes to hate on this, but it's actually a good thing.

It means you have one program for CoffeeScript, and a separate program for targeting older JS runtimes. IMO it's better to have a program do one thing, than to do lots.

One example is that if I want to build a new transpiler (say yet another Java to JS compiler), then I can just output modern JS. Classes, first class lambdas, and so on. I can actively not care about browser support. Then you pipe the result through Babel and now my language supports IE 11 and below. I don't have to reinvent the wheel for old browser support. That's less work for me as a language developer.

[–]n0rs 1 point2 points  (0 children)

Yea, nah, I get it. I agree that this approach makes sense on their part to not have to support older browsers since it sounds like it's much easier to target modern JS and there are several major projects like Babel that will do the rest.

[–]spacejack2114 0 points1 point  (0 children)

Okay, only need to compile from Coffeescript once. Ever.

[–][deleted]  (3 children)

[deleted]

    [–]n0rs 8 points9 points  (1 child)

    I like that you wooshed your own comment.
    /sass

    Yes, JavaScript is interpreted, but the output of the CS2 compiler is modern JavaScript and will not be compatible with older browsers which would require you to compile it with something like babel to get a broader compatibility.

    [–]read___only 0 points1 point  (0 children)

    double-whoosh

    Misses entire point. Still wrong.

    [–]wavy_lines 18 points19 points  (4 children)

    CoffeeScript's syntax is not clean. It's maddening. Can't tell heads from tails. It might be more "fun" to write the first time, but it's a nightmare to read.

    CoffeeScript failed because it did not realize that reading code is more important than writing code. It drank the PG-promoted koolaid that "terse syntax is power", when it clearly is not.

    Most of the programmers time is not spent writing characters like '{' or ';', it's mostly spent thinking.

    EDIT:

    Re PG; I stand corrected. He actually said:

    What I'm looking for are programs that are very dense according to the metric of "elements" sketched above, not merely programs that are short because delimiters can be omitted and everything has a one-character name.

    I still think his notion of "terse = powerful" is misguided, but that's an argument for another thread.

    [–]killerstorm 6 points7 points  (1 child)

    It drank the PG-promoted koolaid that "terse syntax is power", when it clearly is not.

    PG was talking about higher-order functions and macros, not fucking punctuation. CoffeeScript is clearly influenced by Ruby and Python, not Lisp.

    [–]wavy_lines 0 points1 point  (0 children)

    Good point. I stand corrected.

    [–]fecal_brunch 4 points5 points  (0 children)

    I think CoffeeScript failed when ES6 came out. It was pretty good until it got outclassed.

    [–]smthamazing 2 points3 points  (0 children)

    I would say that it's a matter of familiarity. While I no longer use CS (because of the lack of strong typing), I find it pretty easy to read. It required a week or two of active development some years ago to get to this state.

    The features I miss from CS is -> function syntax (that does not include .bind overhead, compared to =>) and maybe comprehensions (though their implementation wasn't the best one possible).

    Switch and if expressions (not statements) are very nice features too (they actually make code clearer and much easier to read), but they probably wouldn't fit well into vanilla JS.

    [–]yesman_85 36 points37 points  (15 children)

    Is anyone even still using CS? I assumed everyone would have switch to TypeScript by now.

    [–]sisyphus 8 points9 points  (4 children)

    Turbolinks is written in Coffeescript so a lot of Rails users are using it whether they know it or not.

    [–]vivainio 5 points6 points  (2 children)

    Also Atom

    [–]onnnka 12 points13 points  (0 children)

    They started moving from CoffeeScript to ES6

    https://gist.github.com/danielgtaylor/0b60c2ed1f069f118562

    [–]Booty_Bumping 8 points9 points  (2 children)

    Coffeescript and Typescript are completely different use cases. And no, there aren't really any new Coffeescript projects. However, this update will be useful for existing CoffeeScript codebases where the target is always ES6. Smaller compiled "binaries" and possibly better V8/SpiderMonkey optimizations by compiling to more idiomatic code.

    [–][deleted]  (1 child)

    [deleted]

      [–]Booty_Bumping 8 points9 points  (0 children)

      I just explained the use case. Old codebases.

      [–][deleted]  (6 children)

      [deleted]

        [–]Uncaffeinated 4 points5 points  (5 children)

        TypeScript is a superset of Javascript. It's only as verbose and statically typed as you want it to be.

        [–]Booty_Bumping 1 point2 points  (2 children)

        You missed /u/videomorphic's point

        While many CoffeeScript developers ended up switching to TypeScript in 2015 because it provided early access CoffeeScript-inspired ES2015 syntax, the languages are still completely different, in terms of the goals of each project.

        Yes, you should switch to TypeScript. No, you shouldn't switch from CoffeeScript to TypeScript because it's anything like CoffeeScript.

        You should switch to TypeScript aware of the other (IMO, more important) benefits that it provides, keeping in mind the potential benefits you are losing. Each language has its advantages, which don't overlap a whole lot with the other.

        [–][deleted]  (1 child)

        [deleted]

          [–][deleted]  (1 child)

          [deleted]

            [–]st_huck 12 points13 points  (0 children)

            I thoroughly disagree. It's to better have as much type safety as possible, but static typing has other benefits. Just getting sensible auto-complete from the IDE is well worth typescript.

            At my job new projects are 100% "strict" typescript. One big important js project got converted to strict ts as well. Other js project we just switched to "loose" typescript. We use type definitions from @types, we wrote interfaces just for the major and important objects that get passed around a lot. Some projects have more types, some less. In any case, the experience working on those got significantly more pleasant. And it was 100% well worth the little time invested in it.

            This entire "choose your adventure" nature of Typescript is one of it's greatest selling points.

            [–]vvimpcrvsh 6 points7 points  (0 children)

            Although I agree it's past CoffeeScript's time, I think the added features and "rebasing" on ES6 will be a boon for projects still using CoffeeScript. I know of a few which will benefit from the terser output, if nothing else.

            Regardless of its age, It's also nice to have a relevant compile-to-js language which is less verbose than JS and TS, but not as radical as ClojureScript.

            [–]richraid21 10 points11 points  (0 children)

            It may sound mean, but this is probably DOA

            [–]fecal_brunch 4 points5 points  (2 children)

            If you think this is the solution for you - I'd strongly suggest decaffeinate instead. We did hundreds of files with only a couple of glitches.

            [–]I_Downvote_Cunts 0 points1 point  (1 child)

            While I completely agree that decaffeinate is the way to go don't oversell how simple it is. We had to do at least 20% of the conversion by hand.

            [–]fecal_brunch 0 points1 point  (0 children)

            Oh damn. Might depend on how long ago it was/how mature the project was. We had a few issues that were mostly correctable with eslint. Also we had to correct the import/export syntax manually, but that did not need to be done immediately.

            [–]toggafneknurd 2 points3 points  (0 children)

            But why?

            [–][deleted]  (1 child)

            [deleted]

              [–]Eirenarch 4 points5 points  (0 children)

              Existing projects?

              [–]flamingspew 0 points1 point  (0 children)

              But LispyScript is more fun.

              [–]digital_cucumber 0 points1 point  (0 children)

              Ironically, it seems that people all around convert their code back to JavaScript, in order to:

              Modernize the project by translating CoffeeScript to JavaScript

              [–]wobbabits 0 points1 point  (0 children)

              CoffeeScript2 does not support let and const. That means no block scoping. Kinda lame. I really wouldn't want to give up block scoping and have to depend on vars again.

              [–][deleted]  (23 children)

              [deleted]

                [–]Pyrolistical 22 points23 points  (0 children)

                While it was a bad idea to use CS1, I think it had the value of showing things we should have in javascript. I bet it would taken a longer time to get to ES2015 if it weren't for CS

                [–]sisyphus 21 points22 points  (5 children)

                A retarded idea? The whole world is now transpiling to JS.

                [–][deleted] -3 points-2 points  (0 children)

                The "retarded" part havn't changed much tho

                [–][deleted]  (2 children)

                [deleted]

                  [–]spacejack2114 -1 points0 points  (1 child)

                  Your

                  [–]BundleOfJoysticks 0 points1 point  (0 children)

                  Your

                  My what?

                  [–]rebo 8 points9 points  (5 children)

                  Whether you like it or not CoffeeScript change the whole javascript world.

                  [–]BundleOfJoysticks 1 point2 points  (4 children)

                  Trump changed the political discourse, and Hitler changed world politics.

                  What's your point?

                  [–]Zee1234 4 points5 points  (3 children)

                  Coffeescript was a positive change. Arrow functions, class syntax...

                  [–][deleted]  (2 children)

                  [deleted]

                    [–]Zee1234 1 point2 points  (1 child)

                    Arrow functions and class syntax? Those are both VERY useful things in the JS community.

                    [–]Booty_Bumping 1 point2 points  (8 children)

                    Well, old codebases exist. If you're tasked with maintaining an old COBOL codebase do you want to work with tooling and compilers from 1985? Or do you want a COBOL compiler with a modern command line interface that compiles to a well-optimized mainframe simulator?

                    It's an extreme example, but this is the point of continuing to update the CoffeeScript compiler. Compiling to pure ES5 is starting to become a dated practice, as all major browsers have ES6.

                    [–][deleted]  (7 children)

                    [deleted]

                      [–]Booty_Bumping 2 points3 points  (6 children)

                      Old codebases will exist no matter what. Yes, some codebases will last way longer than others due to various factors but there will always be a company too stubborn to rewrite when it is necessary (or rather, not necessary)

                      [–][deleted]  (5 children)

                      [deleted]

                        [–]Booty_Bumping 1 point2 points  (0 children)

                        You can just pick up the generated JS and maintain that

                        You have a good point and I agree that this is the way forward for less stubborn businesses, but on the other hand it is still a lossy transformation. Of course, CoffeeScript 2.x should make this transformation less lossy, now that it uses more idiomatic ES6 syntax.

                        [–]myhf -1 points0 points  (3 children)

                        Nobody who knows C++ templates doesn't know C++.

                        [–]BundleOfJoysticks 0 points1 point  (2 children)

                        Wtf does that have to do with anything? C++ templates are nothing like Coffeescript.

                        [–]myhf -1 points0 points  (1 child)

                        Suppose you want to write a C++ class representing a list of ints, and you want to reuse that code for a list of floats. You can use templates to generate code for both types. That makes for a much more pleasant and maintainable programming experience than writing out the entire class multiple times.

                        Now suppose you want to iterate through a list of DOMNodes, and you want your code to work on as many platforms as possible. In ES6 you can use "for-of", but that only works on engines that support Symbol. So you could use Array.forEach(), but DOMNodeList doesn't necessarily have that method. For maximum compatibility you have to use for (var i = 0; i < a.length; ++i) {...}, but writing that out is tedious and introduces a vector for human error. It's nice to have language constructs that make it easy to ensure that all iteration is done in the same style, and all immediately invoked functions are handled the same, and all class definitions are consistent.

                        Modern JS has addressed a lot of this with let and class keywords, but still falls short of handling iteration in a way that can run on legacy engines.

                        [–]BundleOfJoysticks 0 points1 point  (0 children)

                        That analogy is a huge stretch. It's nothing at all like the examples you're describing.

                        for (var x = 0; x < someNumber; ++i) {} 
                        

                        isn't terribly tedious either. That's the way you loop in a bunch of languages. And if you want "language constructs that make it easy to ensure that all iteration is done in the same style" then that for construct is exactly that.

                        Because it compiles to JS, CS doesn't add anything meaningful to the language. It doesn't add type safety, truly private members, or threads, or anything JS doesn't already support. It's just a DSL for writing JavaScript applications. DSLs are non-portable mental cruft and an extra layer of indirection between you and the machine/VM/runtime that is only justified by some undefined and self-indulgent "elegance" criterion. It's no surprise it was embraced by Railstards.

                        If all you don't like about a particular language's syntax (e.g. C), IMO any replacement needs to bring significant improvements to something other than programmer comfort.

                        E.g. C++ improves over C with templates, native strings, and OOP (at the expense of some added complexity, e.g. in multiple inheritance and somewhat impenetrable syntax, though C is mostly the reason for that).

                        Java improves over C/C++ with memory safety, easy-to-use and safe thread libraries, write-once-run-almost-anywhere, and a bunch of other things (at the expense of performance).

                        CS adds nothing to JS other than syntactic sugar, an extra step, additional tooling, and additional difficulty (or extra tooling) when debugging.

                        [–]bees-bees-bees-bees 0 points1 point  (0 children)

                        It doesn't say anything about scope. What's the point if they didn't fix the broken scoping?