Event-driven programming

related topics
{math, number, function}
{system, computer, user}
{day, year, event}
{work, book, publish}
{style, bgcolor, rowspan}

In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions (mouse clicks, key presses) or messages from other programs or threads.

Event-driven programming can also be defined as an application architecture technique in which the application has a main loop which is clearly divided down to two sections: the first is event selection (or event detection), and the second is event handling. In embedded systems the same may be achieved using interrupts instead of a constantly running main loop; in that case the former portion of the architecture resides completely in hardware.

Event-driven programs can be written in any language, although the task is easier in languages that provide high-level abstractions, such as closures. Some integrated development environments provide code generation assistants that automate the most repetitive tasks required for event handling.

Contents

Criticism and best practice

Event-driven programming is widely used in graphical user interfaces because it has been adopted by most commercial widget toolkits as the model for interaction. The design of those toolkits has been criticized for promoting an over-simplified model of event-action, leading programmers to create error prone, difficult to extend and excessively complex application code:[1]

Such an approach is fertile ground for bugs for at least three reasons:

Instead of a low level action-reaction, Miro Samek proposes a better approach using finite state machines to control the interaction logic necessary to define the state changes to incoming events. Hierarchical state machines have also been proposed as a high-level model for reactive programs.[2] The UML language in particular provides a complete specification to represent state machines.

Full article ▸

related documents
Maple (software)
Simula
Queueing theory
Compiler optimization
Wikipedia:Free On-line Dictionary of Computing/E - H
P-code machine
HyperTalk
Z-buffering
Java Servlet
Ada (programming language)
Netlist
Priority queue
Fourth-generation programming language
Unified Modeling Language
Enterprise Objects Framework
Abstract Syntax Notation One
CPAN
Compiler
Universal Turing machine
ANSI escape code
AltiVec
XOR swap algorithm
Chmod
Source code
Object-relational database
Modula-2
Symmetric-key algorithm
Pike (programming language)
Defensive programming
Zope