r/javascript • • Jul 10 '16

The JavaScript language reboot is done

https://medium.com/@velmu/the-javascript-language-reboot-is-done-7bcec4be2cb6#.dy2fyy9j1
41 Upvotes

98 comments sorted by

View all comments

29

u/[deleted] Jul 10 '16

Callbacks obsolete? Seems premature to say so.

10

u/ihsw Jul 10 '16

I think it is.

Callback hell is over, promises and async/await have won.

I challenge you to find any new ES6/TypeScript projects that still use anonymous functions for asynchronous execution.

11

u/gurenkagurenda Jul 10 '16

There are cases where callbacks still make sense though, like event handling.

6

u/Sinistralis Jul 11 '16

Sounds like we need a library to fix this travesty

1

u/gurenkagurenda Jul 11 '16

I think you're joking, but honestly I really do think event handling could use a better abstraction, the same way promises did for procedural async. I don't really know what it would look like though. Something something streams, something something generators.

10

u/namesandfaces Jul 10 '16

I actually find callbacks very manageable with observable streams, just as easy as promises. Code ends up just as comprehensible.

0

u/[deleted] Jul 10 '16

[deleted]

1

u/TheIncredibleWalrus Jul 10 '16

Amen, I can't believe the amount of replies it took for this reply to come up (out of a few agreeing upon the OP's misguided view on callbacks).

3

u/[deleted] Jul 10 '16

I agree. I've never found major issue with callbacks.

IMO, so many of the "problems" with JS are due to the vast majority of people who look at the community and apply fixes/patterns/designs without understand how it actually affects their code.

0

u/TheIncredibleWalrus Jul 10 '16

Callbacks aren't bad because of "callback hell" and the "pyramid of hell", it's about inversion of control and the trust problem

0

u/cosinezero Jul 11 '16
Don’t call my callback too early
Don’t call my callback too late
Don’t call my callback too few times
Don’t call my callback too many times
Make sure to provide my callback with any necessary state/parameters
Make sure to notify me if my callback fails in some way

Oh my god, these apply to every function call in my application! Promises are the hammers to all the nails!

7

u/hahaNodeJS Jul 10 '16 edited Jul 10 '16

I challenge you to find any new ES6/TypeScript projects that still use anonymous functions for asynchronous execution.

...

new Promise(function(resolve, reject) { resolve(); })
.then(function() { console.log('hello'); });

There are two anonymous functions and two callbacks in use here.

0

u/[deleted] Jul 10 '16

[deleted]

14

u/Jafit Jul 10 '16

What's promise hell? Is that where you try to use promises without knowing how they work?

3

u/bighi Jul 10 '16

It's when you make promises you can't fulfill and your looks at you with that look on her face.

0

u/[deleted] Jul 11 '16

[deleted]

1

u/Jafit Jul 11 '16

Can you provide an example of good code layout making callbacks not horrible to use?

0

u/[deleted] Jul 11 '16

[deleted]

→ More replies (3)

1

u/Martin_Ehrental Jul 10 '16 edited Jul 12 '16

I think the part about async work is premature.

It's true for callbacks; I think Promises have replaced them and soon we will have async/await which should ease working with them... So, almost there.

Concerning events, Observables are replacing event listeners. Most frameworks have settles on an observable library, and there will be soon be a standard Observable set of interfaces... hopefully. But we are not there yet and it's still very unstable. We even get new observable libraries popping up.