Higher Order Function, Callbacks Function, Biggest Problem With Callbacks
Higher Order Function
There are functions which take another function as arguments, these are called high order functions.
There are some internal functions which are also available as higher order functions. Let's talk about that
Callbacks Function
This concept technically exists in every language. If you are coming from the world of JavaScript already then this word callbacks is one of those words that most probably you are going to use daily in your programming career.
领英推荐
Higher order functions consume functions as arguments and the function that you pass as argument is called callback function.
Biggest Problem With Callbacks
You might say the callback hell but that is the second disadvantage of the callbacks not first. Let's talk about it -
Writing callbacks is kind of? fun but sometimes callbacks become? problematic. Most of the time if you ask someone hey what is the problem with callbacks you find the answer as callback hell but in my opinion callback hell is not the biggest problem that you have.? Why am I saying that ? Because when you talk to the people and you ask what is the problem with callback they say Callback hell the second follow up question should be how can you improve it ? they will start saying Promises can help us avoid callback hell. The problem is in the concept of promises there are promise hell also. But technically you can't improve callback using promises. After that some people say that the callback problem will be solved using async await but there's async await hell.
There is a bigger problem in callbacks that is technically called Inversion of Control.
The control of your function which was your implementation you have passed the control of how this function should be called to someone else. Means In the context of callbacks, inversion of control is the notion of having code under your control in one part of the program, then handing control over to a callback in another part of the program.