6 ms·
Decaffeinating a Large CoffeeScript Codebase Without Losing Sleep
- orta 9y agoThanks, this is something I've been thinking about for a while.
- sudowork 9y agoNo problem! Hope it comes in handy :).
- smilekzs 9y agoPlain vanilla JS (and therefore TypeScript) still lacks one killer feature from the Coffee family: Null propagation operators (`a ? b` => `a != null ? a : b`, `a?.x` => `a == null ? null : a.x`, etc). Even C# has it.
- sudowork 9y agoI agree, it's one of the features we'll miss. There is a Stage 1 Null Propagation proposal: https://github.com/tc39/proposal-optional-chaining https://github.com/tc39/proposal-optional-chaining
- evan_ 9y agoThere's a babel transform for this in case you want to start using it now, before browsers support it: https://github.com/babel/babel/tree/7.0/packages/babel-plugin-transform-optional-chaining https://github.com/babel/babel/tree/7.0/packages/babel-plugi...
- sudowork 9y agoThanks for the tip! Given some of the lessons we've learned with CoffeeScript, we'll most likely wait until proposals hit at minimum stage 3 before adopting them.
- btown 9y agoI've been waiting for this for years. Even considered forking Babel... it's been a long time coming :)
- smilekzs 9y agoI want to use TypeScript too, which will probably not adopt it until standardization.
- DanRosenwasser 9y agoWe definitely want to implement it! But many parts of that specification are still in flux, so like you said, we'd like to see the proposal stabilize first to avoid problems.
- abritinthebay 9y agoGiven null is generally non-idiomatic in JS (it's there, but most best practices say to avoid it) I think that's likely by design. However the `a?.b` form is coming (it's not just null propagation, it's an Existence Operator). It's called "optional chaining" https://github.com/tc39/proposal-optional-chaining https://github.com/tc39/proposal-optional-chaining
- smilekzs 9y ago> I think that's likely by desig Fine. s/null/undefined The problem still exists.
- abritinthebay 9y agoI think calling it a problem is a bit melodramatic. A cleaner syntax is nice for sure, but it’s not exactly unworkable as is (and promotes flatter data, generally a good thing). But yes, it’ll be nice if/when the new syntax drops.
- Jakob 9y agoThe first one kind of works with `a || b`. Returns b if a is falsey (null, undefined, 0, "").
- smilekzs 9y ago> kind of works !== works
- alanh 9y agoThe other killer feature that is still missing is multi-line regex with inline comments. I know, you shouldn't be writing big regexes if possible… but when you need to, it's so nice to be able to actually explain what the heck you are doing!
- Dirlewanger 9y agoIt's pretty wild having seen CoffeeScript spread like a wildfire in the early 2010s, only to be discarded nearly as fast a couple years later.
- ars 9y agoIt validates my policy of not jumping on every new thing. I loose "nerd cred" for it, but it's better for my clients that way.
- nothrabannosir 9y agoThe only bandwagon I've ever witnessed explicitly was this "I'll lose nerd points for being so anti establishment" thing, that's been going around forever. I loose "nerd cred" for it. Please. Give me a break. Half the people here will fall over themselves agreeing with you and you know it. Heck, I agree with you. Can we please, as a community, get over ourselves? Can we get over this "ermegerd I'm not gonna use the latest JS framework! Guess that makes me 'not cool'! Haha I'm so level headed teehee guiltyyy!" We get it! Most people, the silent majority, don't use new things. We know! We are them. It's ok. Stop. dont humblebrag about how productive you are on Procrastination News. I've never been on Tumblr but I imagine this is what some of it is like. Sorry for singling you out. It's just a bugbear, is all. You're probably a solid guy / girl and I do believe you deliver great value for your clients. Honestly.
- ars 9y agoI've been criticized (by other programmers!) for not going for the latest and newest stuff, so I'm a bit sensitive and glad to have some confirmation that I'm right. I'm not trying to brag (didn't even realize it could be read that way), I'm trying to validate both myself and other people like me.
- arvinsim 9y agoI would guess that nerd cred is not the reason for most people. It's about competitive advantage. Some people just want an edge over other people in their career. Some don't want to miss the "next best thing". Some people just want to be stay relevant and be employed.
- luketheobscure 9y agoThis article is missing one important thing: CoffeeScript now supports native import and export statements, but decaffeinate doesn't. I recently migrated several large codebases and had to escape all the import and export statements (which wasn't very hard), but it got a little hairy where we were directly exporting instead of assigning it to a variable first. I'm going to miss CoffeeScript, but being able to use ES7 features (notably async/await) is worth it.
- sudowork 9y agoWhen we performed our conversion, decaffeinate@2 did support ES2015 import/export - it was actually the default which could be disabled using (`--keep-commonjs`). With decaffeinate@3, you can convert using ES2015 module syntax with the `--use-js-modules` flag. Although we don't plan on using CoffeeScript for the reasons outlined in the article, I do want to mention CoffeeScript 2 does aim to target ES.next features and offer interoperability. Specifically, CoffeeScript 2 does support async/await http://coffeescript.org/v2/#async-functions http://coffeescript.org/v2/#async-functions.
- syntheticcdo 9y agoCoffeeScript 2.0beta has async/await and it works great.
- expertentipp 9y agoHopefully the fate of TypeScript will be the same. If one wants Java in the browser, one can just create Java applets.
- chadrs 9y agoI can't tell if you're joking; applets are being officially deprecated in Java 9 and browsers disable them by default now.
- matthewmacleod 9y agoCoffeeScript was great, and I'm pleased how relatively easy it's been to move away from it now that ES6 offers most of the same benefits. I've recently started moving our existing CoffeeScript + React codebase – it's been okay, though I still miss the terse CoffeeScript syntax. A similar blog post that's helped is Bugsnag's: https://blog.bugsnag.com/converting-a-large-react-codebase-from-coffeescript-to-es6/ https://blog.bugsnag.com/converting-a-large-react-codebase-f...
- meowface 9y agoIf you miss the syntax, why not wait out for CoffeeScript 2? They're going to add all of the ES6 features, to my understanding.
- matthewmacleod 9y agoThere are a few reasons we made the switch: - Familiarity. Most of our team have a little experience with Javascript, but none at all with CoffeeScript. It's not that different, but there's still a cognitive overhead. - Documentation. Almost all documentation for front-end work, especially with React, is in ES6 now. There's an additional overhead in translating it. - React – CJSX was IMO awesome, but there's no ongoing support for it. Embedding JSX in CoffeeScript is less satisfactory. - Webpack. We've had various problems getting features of Webpack 2 to work correctly with pre-2.x CoffeeScript – HMR etc. that only really work with ES6 modules. We could wait for CoffeeScript 2, but it's already becoming a drag on velocity. In short, CoffeeScript was great, but the benefits are much more marginal now. My preference for terse syntax isn't that high a priority for the rest of my team, so I'm happy to take advantage of the more standard ES6 that we can now use.
- mambodog 9y agoActually if you still really want JSX in CoffeeScript, it's now built in: https://github.com/jashkenas/coffeescript/pull/4551 https://github.com/jashkenas/coffeescript/pull/4551