Sometimes dimming the light bulb makes the picture clearer ;-)
Maybe you can share with us how would you improve the code...
I have an aversion to if statements and C-style error handling.
Sometimes dimming the light bulb makes the picture clearer ;-)
Maybe you can share with us how would you improve the code...
I have an aversion to if statements and C-style error handling.
OK, so how how would you form the code?
The idiomatic way of handling different events is to have events be enumerated values and use a switch statement. Sure modern compilers will undoubtly optimize that if cascade to a jump stable but a switch/case statement is more clear.

correct... but the devil is hiding in the details![]()
I would write code that has only one path. A switch statement is a fancy dressed up if statement that is just as ugly underneath.
If you can't simplify your code so that there is only one path, then you're probably making it more complex than it needs to be.
Not really. You're simply representing flaggable states as class variables. If you want it to be better you'd have the class user register callbacks for each particular event and dispatch as the events arrive. This is old hat stuff man.
This is false. A switch statement results in a jump table in the compiled code. There is no multiple comparisons happening - it either hits a case or it defaults.
Also your statement about not having more than one path, dude, code has decision logic built into it. If you write your code so that it only does *one thing* and *only that thing* you've basically codified a particular need into code rather than writing code to handle that need (and others). Your code is actually *worse* in that case because it's not general purpose but entirely "curve fitted" to the particular context-specific case you're using it for.
Having an issue with conditionals is hands down ridiculous.
Not really. You're simply representing flaggable states as class variables. If you want it to be better you'd have the class user register callbacks for each particular event and dispatch as the events arrive. This is old hat stuff man.
This is false. A switch statement results in a jump table in the compiled code. There is no multiple comparisons happening - it either hits a case or it defaults.
Also your statement about not having more than one path, dude, code has decision logic built into it. If you write your code so that it only does *one thing* and *only that thing* you've basically codified a particular need into code rather than writing code to handle that need (and others). Your code is actually *worse* in that case because it's not general purpose but entirely "curve fitted" to the particular context-specific case you're using it for.
Having an issue with conditionals is hands down ridiculous.
Yes, I have problems with people using them because they write shitty state-filled code that I have to debug when I could be doing something more enjoyable.