3 ms·
Why is that easier to read than something like this? function onButtonIsPressed() { doX(); } function onSomethingElse() { doY();
by eurleif 2y ago
Why is that easier to read than something like this?
function onButtonIsPressed() {
doX();
}
function onSomethingElse() {
doY();
}
- krisoft 2y agoWith the second I have to potentially worry about thread safety. What if while i’m busy doing X in response to a button press something else happens and I also need to do Y? With the first version of the code it is pretty obvious what will happen (i will finish doing X and then I will do Y). With the second code I have to read my platform’s documentation to know if it will buffer the second event while the first is handled, or drop it, or call the handler from a different thread.
- eurleif 2y agoThat's a pretty fundamental thing to understand about the platform you're using, isn't it? You learn it once, and then you never have to learn it again. Plus, it's not entirely clear in your example what happens if "something else" occurs, and then while `do_y()` is being executed, a button press occurs. Is the button press event buffered, or is it dropped? Also, given that you're proposing automatic transformation of programs (by the compiler?), and your `while` loop would become shorthand for some unspecified other program, there would potentially be a lot of hidden magic to be aware of. Your program could even be transformed into a program which would process the events in multiple threads.