3 ms·
I typically don't get into these types of conversations but here we go. CoffeeScript is a lovely language by all means and at my company we use it extensively b
by _pdp_ 11y ago
I typically don't get into these types of conversations but here we go. CoffeeScript is a lovely language by all means and at my company we use it extensively because it reduces the amount of boiler plate code by a factor of 10 maybe even 20.
Here is a simple example:
some_func = (callback) -> callback new Error 'boom'
some_func (err) ->
return console.log err if err
console.log 'everything is fine'
The alternative JavaScript version is just too much to read.
This makes huge difference when you write async code and no amount of TypeScript can really help it.
- yareally 11y agoI would disagree about that. TypeScript 1.6 has experimental support for async/await with ECMA6 + promises. TypeScript 2.0 will bring support for it with ECMA 3 and ECMA 5. https://github.com/Microsoft/TypeScript/wiki/Roadmap https://github.com/Microsoft/TypeScript/wiki/Roadmap https://github.com/Microsoft/TypeScript/issues/1664 https://github.com/Microsoft/TypeScript/issues/1664
- mrspeaker 11y agoHave you tried diving into ES6 yet? It's much more terse now that they stole the good bits from coffeescript... let some_func = callback => callback(new Error('boom')); let some_func = err => console.log(err || 'everything is fine');
- warfangle 11y agoI promise I started writing my comment before I saw yours ;)
- warfangle 11y agoThe alternative JavaScript version: let some_func = (callback) => callback(new Error('boom')) let some_other_func = (err) => console.log(err || 'everything is fine') What makes a huge difference is when you write async code with generators, coroutines and promises: let some_func = co(function*() { try { const someData = yield asyncRequest(some_url); console.log('asyncRequest resolved with %j', someData) } catch(e) { console.log('asyncRequest rejected with %j', e); } });
- athenot 11y agoAdding to your point, nesting callbacks is quite elegant in coffeescript. I never understood "callback hell" until I looked at examples in pure JS.