Message Systems in Programming: Part 5 of 7 – Promise and Deferred

Promise and Deferred (or Futures and Completers)

We’ve glossed over asynchronous coding up to this point. Many from languages which have reasonable event API’s (ActionScript) to extremely nice ones (C#), it may not at first look like a problem, or even appear to be an edge case. Coming from ActionScript, it took me years to get comfortable, and understand why, Promises were helpful. Also, many in those languages either create, or have facilities that help create, orchestration code to help mitigate common asynchronous coding issues.

Continue reading “Message Systems in Programming: Part 5 of 7 – Promise and Deferred”

Message Systems in Programming: Part 4 of 7 – Publish Subscribe

Publish Subscribe

Callbacks help objects/classes talk to each other in a less coupled way. Events for many to listen and react. However, for objects that deal with data or business logic, you need a way for them to globally communicate through some sort of event or message bus. Various libraries have sprung up in languages that do not have this natively available, or if the native API doesn’t fit the developer(s) need.

Continue reading “Message Systems in Programming: Part 4 of 7 – Publish Subscribe”

Message Systems in Programming: Part 3 of 7 – Events

Events

Events in JavaScript (and EventEmitters in Node.js) allow 1 to many; meaning 1 dude or many people can listen for the same event without the developer having to add more code to the sender.

Events also solve with finality the parameter order problem. There is only ever 1 parameter: The Event. Callbacks, Promises, and Streams can have none, or many. In dynamic languages, you have no compiler help with this. Since most Events are an object of some type, you can add as many slots as you want without changing the interface between sender and receiver. This slightly improves the ability to refactor. In strongly typed languages, the surface API doesn’t change, only the internal consumption which is often opt-in, thus helping keep OOP things OOP. w00t to the w00t. Moot point is moot.

Continue reading “Message Systems in Programming: Part 3 of 7 – Events”

Message Systems in Programming: Part 2 of 7 – Callbacks

Callbacks

Callbacks are a way be notified of an event and not have to care if it’s synchronous or asynchronous. This could happen immediately or some time later. It’s the “don’t call me, I’ll call you” of programming. It also gives the receiver the power to dictate where they message goes and usually in what scope. In languages that do not natively support blocking, asynchronous programming needs some mechanism to tell you when “things are done”.

Continue reading “Message Systems in Programming: Part 2 of 7 – Callbacks”