Questions tagged [event-programming]

Event-driven programming refers to the programming technique where the flow of the program is driven by recognition and handling of events such as mouse clicks, key presses, etc.

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.

(Source: Wikipedia).

230 questions
138
votes
11 answers

How does an event listener work?

During one of my lectures today about Unity, we discussed updating our player position by checking every frame if the user has a button pushed down. Someone said this was inefficient and we should use an event listener instead. My question is,…
Gary Holiday
  • 1,171
  • 2
  • 8
  • 8
67
votes
5 answers

When should I use event-based programming?

I have been passing callbacks or just triggering the functions from other function in my programs to make things happen once tasks complete. When something finishes, I trigger the function directly: var ground = 'clean'; function shovelSnow(){ …
J.Todd
  • 3,833
  • 5
  • 22
  • 27
65
votes
6 answers

Is an event loop just a for/while loop with optimized polling?

I'm trying to understand what an event loop is. Often the explanation is that in an event loop, you do something until you're notified that an event has occurred. You then handle the event and continue doing what you were doing before. To map the…
60
votes
2 answers

Communication between nested directives

There seem to be quite a few ways of communicating between directives. Say you have nested directives, where the inner directives must communicate something to the outer (e.g. it's been chosen by the user).
Michal Charemza
  • 1,320
  • 1
  • 10
  • 16
58
votes
8 answers

Are events only used for GUI programming?

Are events only used for GUI programming? How do you handle in normal backend programming when something happens to this other thing?
35
votes
6 answers

How to handle initial state in an event-driven architecture?

In an event-driven architecture each component only acts when an event is sent through the system. Imagine a hypothetical car with a brake pedal and a brake light. The brake light turns on when it receives a brake_on event, and off when it receives…
Frank Kusters
  • 726
  • 5
  • 12
33
votes
7 answers

Why do modern operating systems *ever* have perceptible input (keyboard/mouse) lag?

Sometimes computers stutter a bit when they're working hard, to the point where the mouse location freezes for a fraction of a second, or stutters intermittently for a few seconds. This sometimes happens with keyboard input too, even in very basic…
29
votes
1 answer

Why Protobuf 3 made all fields on the messages optional?

The syntax 3 of protobuf made all the fields optional dropping the keywords required and optional from previous proto2 syntax. Reading some comments from developers it seems that it was done for enhancing forward/backward binary compatibility. But…
tonicebrian
  • 413
  • 1
  • 4
  • 6
29
votes
6 answers

Merits of a "Message Passing" system vs. an "Event Based" system

My question is coming from an somewhat uneducated perspective. What are the relative merits of a "message passing" system vs an "event based" system. Why would one choose one over the other? What are their strengths and weaknesses? I would like to…
sylvanaar
  • 2,295
  • 1
  • 19
  • 26
26
votes
3 answers

What should plugins use: hooks, events or something else?

Consider an app that allows plugins to react to its program flow. I know 2 ways to achieve this: hooks and events 1. Hooks Use calls to empty functions inside the main program flow. These functions can be overriden by plugins. For example, Drupal…
Stas Bichenko
  • 3,689
  • 4
  • 24
  • 32
19
votes
4 answers

Event-driven programming: when is it worth it?

Ok, I know the title of this question is almost identical to When should I use event based programming? but the answers of said question have not helped me in deciding whether I should use events in the particular case I'm facing. I'm developing a…
abl
  • 471
  • 3
  • 12
19
votes
7 answers

How to ease the maintenance of event driven code?

When using an event based component I often feel some pain at maintenance phase. Since the executed code is all split around it can be quite hard to figure what will be all the code part that will be involved at runtime. This can lead to subtle…
Guillaume
  • 2,167
  • 1
  • 18
  • 21
18
votes
1 answer

Should I use a command or an event?

The difference between a command and an event in bus communication seems a little vague to me. I know that commands should be executed once only, while an event can be handled multiple times, but still I'm not sure when to use a command or an event.…
Andrzej Gis
  • 973
  • 9
  • 17
18
votes
5 answers

Is event chaining considered good practice?

From time to time I've encountered scenarios where several complex conditions need to be met prior to triggering an event. Furthermore, most listeners also run additional checks to determine the course of action. This got me thinking whether a…
kgilden
  • 521
  • 4
  • 11
16
votes
1 answer

In general how do Event Handlers work?

This is a general topic, How do Event Handlers work? This means behind the scenes - what happens when they are created. I have a rough idea - but would like to have it confirmed.
JHarley1
  • 701
  • 3
  • 8
  • 13
1
2 3
15 16