Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

notjustjay

macrumors 603
Sep 19, 2003
6,056
167
Canada, eh?
Classic programming is like checking a mailbox for your iPad mini package delivery. Is it here yet? Go outside and check for the box. No box? Then go back inside, do something else for a while, go outside later and check again. You spend a lot of time wondering "Is it here yet? Is it time to go check?" You check your watch often because you don't want the package to be sitting out there too long (it could get stolen!) Do you check the door every hour? Every 10 minutes?

In programming terms this is calling polling.

Event driven programming is like having a doorbell. You don't have to "do" anything. Take a nap on the couch. When your iPad mini arrives, the delivery guy will ring the doorbell, and you'll know it's time to get your package. You don't waste time checking the door needlessly or timing yourself.

It can be a little weird to get used to event-driven programming when coming from a "classical" programming background because you are used to writing the code that is actively in control of the computer. What will it do next? Then what? You're not used to code that "does nothing".

With event-driven programming, you throw your program into some kind of "main application loop" that might do absolutely nothing other than sit there and wait for events to happen (kind of like taking a nap on the couch). Then you just worry about the code that will run when something happens.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.