Skip to content

Programming: The dark side of Event Driven Programming

September 9, 2011

(Post below is directed towards programmers, non-programmers might have a hard time understanding)

Let us take a simple example: We have a player-class that has to use resources from various ‘service providers’ (eg other classes in our design). Assume we’ve written our ‘service providers’ as event driven classes – meaning, notifying of a loaded asset using an event. Given this scenario our class will have to contain various onResourceLoaded member functions per ‘service-provider’ it works with. It will look something like this:

While this approach can be employed,  it forces our ‘player-class’ to create a call-back per service-provider (the area in a dotted square) and write some logic to synchronize the resources until the class can make use of all the data. Essentially our player-class has to have (N-service-providers + 1 [update function])  functions at least that all change internal data in our player-class. If our ‘service-providers’ were written in a “ask if resource is available” rather then “we’ll notify you when the resource is available” we gain several advantages with our player-class. 

  1. We no longer have as many member functions imposed on us by service-providers.
  2. We do not have to make sure all our callback-functions sync well with each other in a scattered manner.
  3. We have one function written in a procedural fashion that handles all our logic.
  4. Code execution is very clear: Start to End. Makes debugging much easier as opposed to a scattered event-system. Events would force us to deal with code execution in an undefined order.
If I had to phrase it, I would call this ‘Procedural OOP’. Procedural programming is considered to be some left-over programming paradigm. Though in reality there is still a lot to be gained if it is used well.
Happy Coding,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: