IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New re: Event-driven code can make the flow harder to follow
(* Some of the programmers at our company HQ like to make everything event-driven *)

Even for batch-oriented processes? Event driven is great for interactive stuff, but to use it for batch-like processes is asking for complexity that does not need to be there IMO.

(* But this can lead to a a game of ping-pong trying figure out what's going on *)

What is really fun is recursive events, especially with long chains between each loop, not just self-calling-self.

Is it still called recursion if there are multiple callers in between? Or just "circular"?

Simple recursion is like:

ABBBBBBBBBBBBBB....

(Where each letter represents a routine/method.)

But event-triggered recursion can be like:

ABCDEFGCDEFGCDEFGCDEFG....

Makes debugging nasty.
________________
oop.ismad.com
New Not recursion per se...
What you are thinking of is asynchronous processing of events. Not the same thing as recursion, as the functions are not calling themselves - either directly or indirectly. Instead, you have an event processor that delegates to the procedures as the events are tripped.
New re: Not recursion per se...
What you are thinking of is asynchronous processing of events. Not the same thing as recursion, as the functions are not calling themselves - either directly or indirectly. Instead, you have an event processor that delegates to the procedures as the events are tripped.

Synchronous or Asynchronous is not the issue, as I see it. It is "run-away" triggers. Event A could trigger event B, which could trigger event C, which could trigger event A *again*, repeating the cycle. Being Sync or Async may make very little difference.
________________
oop.ismad.com
New But that's not quite the same as recursion.
As far as I understand it, the difference lies in how the routines handle pre-emption: do they abandon the earlier calls, or do they try to (eventually) service all requests? This is also tangled up with how triggers are addressed: Are they queued, or are they taken immediately? Hardware IRQ is usually done the latter (though the interrupts can be queued in hardware) but by contrast Windows message handling is mostly the former. An IRQ routine must decide whether it allows itself to be pre-empted with additional calls or not. Code hanging off a traditional Windows message loop doesn't have that concern: there are well defined points where the message-handler can get called and that isn't usually from within the handler itself.

You mentioned runaway triggers. If that's possible, the design should think of that and have some defenses in place. Referring back to the Windows message loop again; certain types of frequent messages (mouse updates are the canonical example, IIRC) are co-alesced into fewer messages by the queue handler. This means your message handler doesn't get bombarded by out-of-date mouse movements that it can't handle fast enough. Then, too, this is largely possible because the message handler must usually complete and exit before Windows will hand it another message to process.

Tackling trigger/message flooding is not really the same as bounding recursion.

Wade.

"Ah. One of the difficult questions."

Expand Edited by static Sept. 17, 2002, 02:54:04 AM EDT
     The Myth of Code-centricity - (tonytib) - (15)
         Agreed that his answers only work in one problem domain - (ben_tilly) - (2)
             Remember where the article appeared - (tonytib) - (1)
                 I did - (ben_tilly)
         What if the tools have bugs? - (ChrisR) - (6)
             Good comments! (so obviously I agree. :)) - (a6l6e6x)
             Event-driven code can make the flow harder to follow - (tonytib) - (4)
                 re: Event-driven code can make the flow harder to follow - (tablizer) - (3)
                     Not recursion per se... - (ChrisR) - (2)
                         re: Not recursion per se... - (tablizer) - (1)
                             But that's not quite the same as recursion. - (static)
         He just described NextStep (now Apple Cocoa) - (tuberculosis) - (1)
             I also thought anonymous collab was the most interesting - (tonytib)
         re: Demoting source code - (tablizer) - (2)
             lets put this in cruder human terms - (boxley) - (1)
                 I can't translate that analogy into SW engineering issues -NT - (tablizer)

My name's Friday. I carry a badge.
65 ms