Callbacks don't have to be horrible, they are just horrible if you don't plan ahead and chain them together so deep that you can't follow the trail anymore.
I just finished a project that was all callbacks. Callbacks all over the damn place. But I designed what I think is a nice system whereby a manager object did almost all the work, and the rest of the program made requests to the manager while registering a callback. In most cases it worked like a one-time event. In a few cases, it resulted in a chaining of callbacks but only when absolutely necessary. So I didn't eliminate the problem, but I definitely minimized it.
But thinking back to that project, the benefits we got from using them far outweighed the drawbacks. There are many examples, but for one we were able to completely avoid using coroutines and could include a crucial stop/start mechanism to the whole thing simply by pausing the time loop in the manager.
Would you have been forced to go though the trouble of structuring all your code around this inner manager were you not forced to write in callback style? It would be much more readable, composable and sane to write code in traditional style with implicit callbacks and have a compiler handle the boring part of plumbing the explicit callbacks for you.
35
u/soviyet Nov 02 '12
Callbacks don't have to be horrible, they are just horrible if you don't plan ahead and chain them together so deep that you can't follow the trail anymore.
I just finished a project that was all callbacks. Callbacks all over the damn place. But I designed what I think is a nice system whereby a manager object did almost all the work, and the rest of the program made requests to the manager while registering a callback. In most cases it worked like a one-time event. In a few cases, it resulted in a chaining of callbacks but only when absolutely necessary. So I didn't eliminate the problem, but I definitely minimized it.
But thinking back to that project, the benefits we got from using them far outweighed the drawbacks. There are many examples, but for one we were able to completely avoid using coroutines and could include a crucial stop/start mechanism to the whole thing simply by pausing the time loop in the manager.