Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: how organize code

by patcat88 (Deacon)
on Nov 29, 2011 at 08:01 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-20 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found