+ 6
WHAT IS GUARD CODE?
A part of programming methodology?
2 Réponses
+ 3
I realize your question is about c++ so please just take this as "the concept from another language":
To guard against being evil to other users, I often use the following pattern. It is because Javascript can cause Sololearn to unexpectedly reset when "animation timers" (especially those causing errors) are left running when SoloLearners navigate away from my app.
This code not only cancels the next animation event, but it stops the event that is (with almost 100% certainty) already in the event queue:
// pseudocode
stopped = false
animator {
if(stopped) return // re-entry guard
// guarded code
}
// exit guards
before app exit and on error {
// prevent queued event
stopped = true
// prevent new events
clear animation timer
}