4 ms·
It depends what you are doing. If you are implementing some web application I can imagine that this callback style would be very handy. For example, suppose y
by jgrahamc 17y ago
It depends what you are doing. If you are implementing some web application I can imagine that this callback style would be very handy.
For example, suppose you have an email application and on the page there's an area with contact information. You could fire off the SQL query to get the contact database and have the callback populate the contact information box on screen when it's ready.
The rest of your program just carries on doing whatever it needs to do: which may be nothing... the entire program can be event driven and waiting for events to happen (like the user clicking somewhere).
This style of programming takes a little getting used to, but you don't need to have some linear piece of code going around checking to see what needs to happen next.
If in the example of contact information you need something else to happen once the box is populated then I imagine you'd fire some event that tells your program what to do.
- amix 17y agoI agree on the usefulness, but I don't think it would produce more elegant code and I don't think the event driven paradigm should be used for everything (even if there are some advantages). This said, event driven programming is quite natural when doing network or GUI programming and most good network and GUI frameworks are event driven. Most database libraries or system libraries aren't.