147 votes
Accepted

How does an event listener work?

Unlike the polling example you provided (where the button is checked every frame), an event listener does not check if the button is pushed at all. Instead, it gets called when the button is pushed. ...
Robert Harvey's user avatar
106 votes

Are events only used for GUI programming?

Nope. They're really handy for implementing Observers and making sure that classes are closed to modification. Let's say we have a method that registers new users. public void Register(user) { ...
RubberDuck's user avatar
  • 8,931
56 votes

How does an event listener work?

An event listener akin to an e-mail newsletter subscription (you register yourself to receive updates, whose transmission is later initiated by the sender), rather than endlessly refreshing a web page ...
Alexander's user avatar
  • 4,420
53 votes

Are events only used for GUI programming?

Nope. A classic example of events being used in non-GUI logic are database triggers. Triggers are code that gets executed when a given event happen (INSERT,DELETE, etc). Seems like an event to me. ...
Tulains Córdova's user avatar
38 votes

How does an event listener work?

The short, unsatisfactory answer is that the application receives a signal (the event) and that the routine is only called at that point. The longer explanation is a bit more involved. Where do ...
Sklivvz's user avatar
  • 5,252
31 votes
Accepted

Event-driven programming: when is it worth it?

Follow the KISS principle: Keep It Simple, Stupid, or the YAGNI principle: You Ain't Going to Need It. You can write the code like: void updateSpecialData() { // do the update. backupData(); ...
Winston Ewert's user avatar
28 votes
Accepted

Why Protobuf 3 made all fields on the messages optional?

proto3 makes a number of changes aimed (as I understand it) at making it far more usable in cross-platform scenarios. Explicit tracking of "assigned" vs "not assigned but reporting the default value" ...
Marc Gravell's user avatar
  • 2,837
27 votes

Are events only used for GUI programming?

Event-based programming is actually also used for highly performant server programming. At a typical server workload, much of the time processing a result actually comes from I/O. For example, ...
ArTs's user avatar
  • 720
26 votes

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

As you may have noticed, there's a category of application that tries really hard to avoid input lag and only occasionally fails at doing so: games. Even then it's not uncommon for players to notice ...
pjc50's user avatar
  • 12.6k
25 votes

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

I would like to answer this question from more of a high-level, marketing perspective than a more low-level, technical one. All of the current mainstream Operating Systems are so-called general ...
Jörg W Mittag's user avatar
20 votes

How does an event listener work?

Terminology event: A type of thing that can happen. event firing: A specific occurrence of an event; an event happening. event listener: Something that looks out for event firings. event handler: ...
Nat's user avatar
  • 1,073
20 votes

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

Why can't (or why don't) operating systems absolutely prioritise user input (and repainting thereof) in threading and process scheduling? Even if the operating system tells the application about the ...
Caleth's user avatar
  • 10.7k
19 votes
Accepted

Should I use a command or an event?

In principle, a command describes a request that is to be executed, whereas an event describes something that has happened: A command requires some action to be performed by a processor, and this ...
Christophe's user avatar
  • 75.9k
18 votes

Why is there a shift towards asynchronous and event driven programming?

The "async" approach better facilitates human reasoning. When most people drive, they don't need to concern themselves with how every element of the car is interacting. Forget the tires - ...
TheRubberDuck's user avatar
14 votes
Accepted

How do I deal with side effects in Event Sourcing?

How do I deal with side effects in Event Sourcing? Short version: the domain model doesn't perform side effects. It tracks them. Side effects are performed using a port that connects to the ...
VoiceOfUnreason's user avatar
13 votes

Event-driven programming: when is it worth it?

The example you describe of a simple data, where the modification triggers some effect can perfectly be implemented with the observer design pattern: this is simpler to implement and maintain than ...
Christophe's user avatar
  • 75.9k
11 votes

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

In my experience, on most computers I have ever used, this is usually caused by inappropriate swapping to disk. Every other cause (such as operating system locks) is significantly less common. When ...
user253751's user avatar
  • 4,863
10 votes

Are events only used for GUI programming?

Events are also heavily used in network programming (e.g. Nginx) to avoid expensive busy-wait loops and instead provide a clean interface to know exactly when a certain operation is available(I/O, ...
edmz's user avatar
  • 201
10 votes

How can message queues improve scalability?

It's not that queues are more scalable, its the fact that two services communicating through queue means the communication is asynchronous. Asynchronous communication is far more scalable than ...
Matan Shabtay's user avatar
10 votes

Why is there a shift towards asynchronous and event driven programming?

Fundamentally the answer comes down to the fact that threads are not free. There is overhead associated with each thread. I found this article which is written by former Intel Engineer Arch D. ...
JimmyJames's user avatar
  • 26.1k
9 votes
Accepted

Why use plus equals += for event registration?

If you ever try to write something like: window.onClick = myHandler; You will get a compiler error about event handlers only allowed on the right side of a += or -=. The C# compiler team was smart ...
Ron Beyer's user avatar
  • 186
9 votes

How does an event listener work?

Pull vs Push There are two main strategies to check if an event happened, or a specific state is reached. For example, imagine waiting for an important delivery: Pull: every 10 minute, go down to ...
Matthieu M.'s user avatar
  • 14.7k
8 votes

Why is there a shift towards asynchronous and event driven programming?

A lot of event driven programming is because the applications are event driven. You're running code to handle a button click, or a received packet, or a timer expiring. That sort of code is actually ...
Karl Bielefeldt's user avatar
7 votes
Accepted

Achieve atomicity between two separate systems

"Atomic" means that the process appears to have happened instantaneously, or at least it cannot be interrupted. Its possible to have atomic distributed processes, but its not easy, e.g. you could do ...
Justin's user avatar
  • 1,728
7 votes

Dealing with data arriving at a different times

Don't view the result as the outcome of a request, but as the followup of an event. The question doesn't specify much so I can only speak in abstract terms. I believe the following to be the best ...
Lacey's user avatar
  • 161
7 votes
Accepted

Temporal logic as a programming language paradigm?

TLA+ isn't so much a general purpose language, but... One of the benefits of using TLA+ to investigate the bug is that once you can reproduce the bug, it’s easy to try alternative fixes. The bug in ...
Robert K. Bell's user avatar
6 votes
Accepted

Is event sourcing only for when writes are rare?

So, what am I missing? Taking a guess. The first thing that you may be missing is that you only need to reload the events for the state you are rebuilding. If you can model your transaction ...
VoiceOfUnreason's user avatar
6 votes
Accepted

Where should event debouncing be done, in the emitter or consumer?

I'd say that the consumer should take care of that. This way the emitter does not need to make any assumptions about how the consumer wants to handle the event. Maybe in a very defined context, where ...
Zalomon's user avatar
  • 1,200
6 votes
Accepted

Is an event based approach the right way to think about this problem?

Reading your question and the other answers, I am under the impression there is some confusion caused by the fact the term "event based system" often is used differently from the way it is used in ...
Doc Brown's user avatar
  • 203k

Only top scored, non community-wiki answers of a minimum length are eligible