As a C programmer working with a large codebase, I have come to HATE callbacks. Seriously, the worst feeling ever is tracing through a huge function tree, only to run into function pointer dereference. Then you have to go on a wild goose chase to find out when, where and what it will be assigned to. STATIC TYPES PEOPLE.
What does it have to do with static typing? Function pointers are perfectly valid types. Also, can't you just use a debugger?
Callback Hell (2016)
41–50 of 170 posts
Re: Callback Hell (2016)
#42Re: Callback Hell (2016)
#43As a curious and perhaps naive aside, I've been wondering why the programmer should need to care about asynchronous execution of code at all. Can't it all be abstracted under a procedural layer and let the OS worry about not blocking anything? The advent of promises, async.js, and other paradigms tell me that people still kind of want to write code that does one thing after another, then another, then another.
That's how it's done in Go. You write plain, "blocking" code, and if it blocks, the Go runtime will just schedule another goroutine (green thread). In Go there's no need for callbacks or littering your code with `await` keywords to write concurrent software.
Also I agree with the coroutine LUA rationale you can read in the link in this same thread. It appears that with Go I still need to alter my own code to use libraries that are written to run async or am I wrong?
Re: Callback Hell (2016)
#44Re: Callback Hell (2016)
#45Re: Callback Hell (2016)
#46A website? Really? Why not just write an article on medium?
Re: Callback Hell (2016)
#47Lot of blabbling for a simple concept: do not abuse nesting. It's the case with control statements, it's still the case with functions, and even more with async functions. Oh, and callbacks definitely exist in other languages, like C. What's the deal with this trend of setting up a whole website for a (basic) blog post?
"Simple concept" is subjective. I'd bet that discussing "simple concepts" with an engineer or scientist would likely cause your mind to grasp and instinctively try to relate to your own memorization of facts. But that shouldn't preclude you from discussing what you do know, or for that matter, sharing it with the world.
Re: Callback Hell (2016)
#48However they can already be used in Node with the "--harmony-async-await" flag (and without flag in the upcoming Node 8).
Re: Callback Hell (2016)
#49Callbacks of course have the drawbacks mentioned. Sure, you can separate the functions, smaller functions and that too is preferred, but still you get code that can be difficult to reason about and read.
Promises, for all the hype, in my view clearly did not help matters much. Promise code can be as weird looking or worse than callback code. Promises did not solve the problem.
Async/await IS the solution. I've started converting callback and promise code to it. It's a great new enhancement.
Re: Callback Hell (2016)
#50Earlier quoted context omitted.
Yeah, I messed it up when quickly typing the code without thinking, it should've been JSON.parse, I fixed it now. Also regarding that article: you can call async functions from non-async functions - you will simply get the Promise object instead of the data. If you're using TypeScript, your editor will immediately highlight the error if you try to use that Promise object as though it were the data, so zero chance of…
> Also regarding that article: you can call async functions from non-async functions - you will simply get the Promise object instead of the data. async function() getZ(){ return promise } function() getX(){ return x = y * getZ() } // sync call globally. let x = getX(); // NaN async/await makes things more readable, it doesn't change the issue of leaky abstraction and you need to know whether the call is blocking or…
If not, then the problem is really no different from not knowing what your functions are returning (are they returing a Promise object? are they returning the data itself?). Not knowing the return type of the functions you use is hardly something new. You would have the exact same issue with functions that take callbacks.
See the link I sent there https://goo.gl/vDk3Gz - you can hover over all the variables and functions (once the editor fully loads), try typing "n.", hover over the highlighted errors, etc. The tooling takes care of everything.