pages tagged programmingyakkinghttp://yakking.branchable.com/tags/programming/yakkingikiwiki2016-05-11T11:00:15ZEvent driven programminghttp://yakking.branchable.com/posts/event-driven-programming/Daniel Silverstone2016-05-11T11:00:15Z2016-05-11T11:00:06Z
<p><a href="https://en.wikipedia.org/wiki/Event-driven_programming">Event driven programming</a> is <a href="http://c2.com/cgi/wiki?EventDrivenProgramming">a style of programming</a> which essentially
boils down to the concept of <a href="http://searchcloudapplications.techtarget.com/definition/event-driven-application">a program being a consumer</a> of a
<a href="https://www.techopedia.com/definition/7083/event-driven-program">stream of events</a> to which the programmer creates code to react. This style
of programming is very popular in software which has to interact with a user
directly since it very readily lends itself to user interface programming.</p>
<p>Commonly such programs consist of some amount of setup, then an <a href="https://en.wikipedia.org/wiki/Event_loop">event loop</a>
which <a href="https://en.wikipedia.org/wiki/Event_dispatching_thread">dispatches</a> <a href="https://en.wikipedia.org/wiki/Event_(computing)">events</a>. What is interesting is that once you get used
to writing software in an event driven fashion then you start to find such
event loops in the most unexpected of places. A little while ago, we talked
about <a href="http://yakking.branchable.com/posts/state-machines-in-c/">state machines</a> and they are useful tools for managing event driven
programs because they are inherently an event processing model.</p>
<p>Your homework for today is to go and look at projects you have and consider if
they have event loops in them, and if so, look at whether or not you've state
machines handling those event streams. Once you've done that, have a look
around in other software and try and identify event loops in different kinds of
software. To get your started, most UI toolkits are event-driven, as is the
Minecraft mod called <a href="http://computercraft.info/wiki/Os.pullEvent">Computercraft</a>.</p>
Message Queueshttp://yakking.branchable.com/posts/message-queues/Daniel Silverstone2015-08-12T11:00:13Z2015-08-12T11:00:07Z
<p><a href="https://en.wikipedia.org/wiki/Message_queue">Message queues</a>, at their heart, are ways to get little packets of
information (messages) from one place to another in some sort of order. Queues
are often used to communicate between processes (and in some cases between
systems). They vary from the simplest <a href="http://linux.die.net/man/7/mq_overview">POSIX message Queues</a> to the much more
powerful <a href="https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol">AMQP</a> implementations such as <a href="https://www.rabbitmq.com/">RabbitMQ</a>, <a href="https://activemq.apache.org/apollo/">Apache Apollo</a>, or
<a href="http://azure.microsoft.com/en-gb/services/service-bus/">Windows Azure Service Bus</a>. There is also the no-broker needed <a href="https://en.wikipedia.org/wiki/%C3%98MQ">ØMQ</a>, or
its lightweight counterpart <a href="http://nanomsg.org/">nanomsg</a>, for those who like the AMQP behaviour
but want something which doesn't need a broker.</p>
<p>The varying levels of complexity of message bus extend from simply passing
messages in the order they were added from sender to receiver (like a socket
might), through priority ordering, to the more complex <a href="https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">PUBSUB</a>, <a href="https://en.wikipedia.org/wiki/Request%E2%80%93response">REQREP</a>,
or <a href="http://nanomsg.org/v0.5/nn_pipeline.7.html">PIPELINE</a> patterns. The pattern which works best for your workload will
be workload dependent, and the appropriate complexity of solution will depend
on your expected scalability needs and deployment methodology. Whatever your
problem, and whatever the implementation language you've chosen, there are
plenty of bindings out there to such a wide variety of message queue
implementations that before you think about writing your own job queue, why not
take a look at one of those which already exist.</p>