Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
laziness, impatience, and hubris
 
PerlMonks  

Re: how organize code

by patcat88 (Chaplain)
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.


Comment on Re: how organize code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://940542]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-04-21 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls