Hacker Newsnew | comments | ask | jobs | submitlogin
jblow 532 days ago | link | parent

Callback Hell is certainly a real thing. I decided 12 years ago that I would never use callbacks if I could avoid it (the only wai you can't avoid it is if an API forces you to use them); I have never looked back. Regular, simple, straightforward imperative flow control is a very powerful thing, and any time you give it up or make it more squishy and indirect, you had better be getting something big in return. Usually you aren't.

That said, what the article proposes as a solution is bananas. You don't need to do crazy functional acronym things; just don't use callbacks. Good C/C++ programmers in the field where I work (video games) do this all the time. It's not hard except that it requires a little bit of discipline toward simplicity (which is not something exhibited by this article!)



tactics 532 days ago | link

Actually, you're wrong. This is bananas (based on very closely related FPR concept)

http://www.haskell.org/haskellwiki/Reactive-banana

Secondly, you come off sounding defensive and ignorant. This is a new programming paradigm. Hopefully it will give people new ways to approach the same difficult problems. (And I really hope you believe GUIs are inherently difficult...)

No one is twisting your arm to learn FPR. If callbacks work for you in your job, then stick with what works.

-----

jblow 532 days ago | link

When I was in college, and shortly afterward, I was very much into "new programming paradigms" and would get excited about lazy evaluation or continuations or whatever was the new cool idea going around. I have designed and implemented several programming languages built around new / wacky features; the most recent of these was ten years ago.

What you are hearing now is not ignorance, it is experience. I am a tremendously better programmer than I was in those days, and the way I got better was not by getting excited about wacky ideas; it was by really noticing what really works, and what doesn't; by noticing what are the real problems that I encounter in complicated programming projects, rather than what inexperienced / pundit / academic programmers tell me the problems are.

Clearly you didn't really read my comment, though, since you are saying "If callbacks work for you in your job..." and my entire point is that callbacks are terrible.

-----

jblow 531 days ago | link

Also, no, I don't believe GUIs are inherently difficult. I do think most GUI libraries are just terrible though, because they have bought into bad GUI paradigms.

If a GUI is your example of something that is difficult, we are just living in different worlds and it's a challenge to have a productive conversation. I think a difficult task is something like "make this ambitious AAA game run on the PlayStation 3 performantly". That is pretty hard.

-----

Evbn 531 days ago | link

FRP isn't new. It is almost as olds as, or older than JavaScript

-----

pkaler 532 days ago | link

Boost bind and fast delegates do certainly suck. (I used to work in games in a past lifetime.) But this is most certainly a C/C++ problem.

In Objective-C, the @protocol keyword gives the language first class delegation and works really, really well. More details here: http://developer.apple.com/library/ios/#documentation/Cocoa/...

With respect to the original article, he's talking about callbacks with respect to Node.js. That's not a callback issue. Async is unnatural for the mind to grasp. What did he expect?

-----

jblow 532 days ago | link

I don't see it as fundamentally different. Callback means some or all of: "I don't know when or where I am being called from, or what the state is of the rest of the program at this time." All of those are bad things if you are trying to write robust software, so you want to avoid them unless there's a really good reason.

-----

wwweston 532 days ago | link

> Callback means some or all of: "I don't know when or where I am being called from, or what the state is of the rest of the program at this time."

This sounds a lot like what function means.

-----

jblow 532 days ago | link

Nope, because you can do static analysis (a.k.a search through your program text) to find out who calls a function and when. The whole point of a callback is that this doesn't work.

-----

Evbn 531 days ago | link

How does that help with program state, which changes based on user input?

-----

pkaler 532 days ago | link

"I don't know when or where I am being called from, or what the state is of the rest of the program at this time."

Gotcha.

A parent object should own a child object. The parent can directly call a method on a child. The child object shouldn't really know about the parent. Hence, it uses a callback/delegate/protocol.

Callbacks are a mess if there isn't a clear parent to child relationship.

-----

jblow 532 days ago | link

I don't believe that parent/child relationships are a good way to structure programs. I use them sometimes, but very rarely. (Current codebase is 180k lines of C++).

-----

Quiark 532 days ago | link

Ok, I understand that you don't use callbacks. But you forgot to mention what you use instead of them, in situations such as described in the article. Polling?

-----

jblow 531 days ago | link

It depends on what the application looks like. The most straightforward and robust thing is to block on events. But if you are doing tons of this kind of thing, and the data is relatively self-contained and packageable, then I would do something like spawn a worker thread that gets the data and then puts the data into a result list (that, again, the main program blocks on).

-----

allertonm 531 days ago | link

If you are coding for the browser, neither of the options you suggest are available to you. Now what?

Answer: you do it with callbacks, because they are literally the only mechanism available. Welcome (back) to callback hell.

-----

jblow 531 days ago | link

Hence my caveat about not being able to avoid it if an API forces you to use them.

But if I were making a replacement language that runs in the browser, among the highest priorities would be to make it not work via callbacks.

-----

chipsy 532 days ago | link

What do you do for networking, though? That seems to be the motivation to introduce callbacky code in web programming.

(FWIW my own architectures tend to turn callbacks into queues and polling.)

-----

jblow 532 days ago | link

Just like a C++ program would, you have a loop that blocks on network input. This has been solved since the 1970s.

-----

Evbn 531 days ago | link

And then how do you use the other 99% of your CPU? Just by extra machines every time a network call hangs? Add threads, and then you gave a whole new can of expensive worms.

-----




Lists | RSS | Bookmarklet | Guidelines | FAQ | DMCA | News News | Feature Requests | Bugs | Y Combinator | Apply | Library

Search: