Event Driven Programming

ImprimirCitar

Event-driven programming is a programming paradigm in which both the structure and the execution of the programs are determined by the events that occur in the system, defined by the user or that they provoke themselves.

To understand event-driven programming, we can oppose it to what it is not: while in sequential (or structured) programming it is the programmer who defines what the flow of the program will be, in event-driven programming it will be the user himself—or whatever is running the program—directs the flow of the program. Although in sequential programming there may be an intervention from an external agent to the program, these interventions will occur when the programmer has determined it, and not at any time as it can be in the case of event-driven programming.

The creator of an event-driven program must define the events that will be handled by their program and the actions that will be performed when each event occurs, known as the event manager. The supported events will be determined by the programming language used, by the operating system and even by events created by the programmer himself.

In event-driven programming, initializations and other initial code will be carried out when the program begins, and then the program will be blocked until some event occurs. When any of the events expected by the program takes place, the program will start executing the code of the corresponding event handler. For example, if the event consists of the user clicking the play button on a movie player, the event handler code will be executed, which will cause the movie to be displayed on the screen.

A clear example is found in the Lexical and Visual Basic programming systems, in which each element of the program (objects, controls, etc.) is assigned a series of events that will be generated by said element, such as pressing a mouse button over it or the redraw of the control. Or in Javascript that assigns event handlers to which respond to events on a web in the case of the browser or to events produced by emitter objects in the case of NodeJS.

Event-driven programming is the basis of what we call user interface, although it can also be used to develop interfaces between Software components or kernel modules.

In the early days of computing, programs were sequential, also called Batch. A sequential program starts, reads input parameters, processes these parameters, and produces a result, all in a linear fashion and without user intervention while it runs.

With the appearance and popularization of PCs, the software began to be demanded for uses far removed from the academic and business classics for which it was needed until then, and it became clear that the classic programming paradigm could not respond to the new interaction needs with the user that arose as a result of this fact.

Event detection

In contrast to the classical model, event-driven programming allows you to interact with the user at any time during execution. This is achieved because the programs created under this architecture are made up of a permanent external loop in charge of collecting the events, and different processes that are in charge of treating them. Usually, this outer loop remains hidden from the programmer who is simply in charge of handling the events, although in some development environments (IDEs) its construction will be necessary.

Example of event-driven program in pseudo language:

While (true){
Switch (event){
case mouse_button_down:
case mouse_click:
case keypressed:
case Else:
!
!

Problem

Event-driven programming is an added complication compared to other programming paradigms, because the flow of software execution is beyond the programmer's control. In a way, we could say that in classical programming the flow was in the hands of the programmer and it was the programmer who decided the order of execution of the processes, while in event-oriented programming, it is the user who controls the flow and decides.

Let's take as an example of the existing problem, a menu with two buttons, button 1 and button 2. When the user presses button 1, the program is in charge of collecting certain parameters that are stored in a file and calculating some variables. When the user presses button 2, said variables are shown to the user on the screen. It is easy to realize that the indeterminate nature of the user's actions and the characteristics of this paradigm can easily lead to the fatal error of pressing button 2 without previously having pressed button 1. Although this does not happen if you have take into account the properties of these buttons, making it inaccessible to press button 2 until button 1 has been previously pressed.

GUI's / Graphical User Interfaces

With the evolution of event-oriented languages, the interaction of the software with the user has greatly improved, allowing the appearance of interfaces that, apart from being the program's communication channel with the user, are the appearance of the program itself. These interfaces, also called GUI (Graphical User Interface), have been the essential tool to bring computing closer to users, allowing in many cases, beginners to use intuitively and without the need for great knowledge, the software that has helped to improve productivity in many tasks.

One of the peripherals that has become more important after the appearance of event-driven programs has been the mouse, thanks also in part to the appearance of modern operating systems with their graphical interfaces. These usually direct directly to the internal controller that is intertwined with the algorithm.

Visual development tools

Over time, a new generation of tools has been appearing that include code that automates part of the most common tasks in the detection and treatment of events.

The visual programming environments that combine a graphical design tool for the GUI and a high-level language are particularly noteworthy. Among these tools is the well-known Visual Basic, a language highly appreciated by beginners due to the ease of developing software in a short time and with little knowledge, and reviled by many others due to its lack of efficiency.

Languages

Web

  • ActionScript

Windows Desktop

  • Visual Basic
  • Visual Object
  • Visual C++
  • Visual C#

.NET Framework (Windows Desktop and Web)

  • Visual Basic.NET
  • C#
  • J#
  • Léxico

Others

  • NesC
  • AS3

Libraries

C and C++

  • Qt
  • GTK+

Java

  • AWT
  • Swing
  • SWT
  • JavaFX

Web

  • ASP.NET (Mediator Javascript with the Code-behind Model)

Contenido relacionado

History of operating systems

An operating system is the set of programs of a computer system that manages hardware resources and provides services to software application programs. On...

ECS

Enhanced Chip Set is the name used for the extended version of the original Commodore Amiga chipset...

Multiple Arcade Machine Emulator

MAME is a free and code multipurpose arcade machine emulator open, which replicates the hardware of these computers for operation on home computers and other...
Más resultados...
Tamaño del texto:
Copiar