Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: how organize code

by patcat88 (Deacon)
on Nov 29, 2011 at 08:01 UTC ( #940542=note: print w/replies, xml ) Need Help??

in reply to how organize code in callback mode

Unless its an event loop with sleeping between events, callbacks are terrible. The parameters your callback is called with is never documented in POD. How can you interleave data from 2 callback based APIs without saving it in a global? What if you found the data you need on the 50th callback run, and you don't want the caller API to run you 10000 more times? How do you quit the callback enumeration loop? Function based enumerations (start() then get() #X times then end() ) are better. Or a batch get() that gets how ever many records you want to swallow in one shot (20 at a time for example). Callbacks are evil unless you have an event loop that kernel sleeps between events. KISS. I find APIs that return flags are much better documented and easier to use than APIs where you register a callback for each flag to run when the enumeration system sees it. Imagine if DOM didn't exist and all browsers only have SAX engines to manipulate the page tree HT/XML. This post isn't specific to you, just all callback APIs.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://940542]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-01-24 06:12 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (255 votes). Check out past polls.