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.
...
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) {
...
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 ...
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.
...
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 ...
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();
...
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" ...
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, ...
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 ...
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 ...
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: ...
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 ...
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 ...
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 - ...
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 ...
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 ...
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 ...
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, ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
event-programming × 230architecture × 38
c# × 26
microservices × 26
design-patterns × 22
design × 19
javascript × 15
domain-driven-design × 14
event-sourcing × 14
asynchronous-programming × 12
event-handling × 11
.net × 9
java × 8
object-oriented × 8
multithreading × 8
gui × 8
cqrs × 7
message-queue × 7
event × 7
object-oriented-design × 6
pubsub × 6
architectural-patterns × 5
apache-kafka × 5
programming-practices × 4
web-development × 4