lundi 28 juin 2021

Simplifying Control Flow

I am using flags to control the flow of my program. The program is a stateful module which is repeatedly called. Flags represent its internal state. The state has multiple dimensions like initialized actionAlreadyChosen rewardAlreadyGiven explorationFinished ... each of which is valid for one object in a set of many. I.e. those states are also to be taken per object managed by my module.

I can't change the architecture of the caller nor any other behaviour from outside. That's the justification for this bookkeeping with internal states.

Now I got annoyed about the complexity of the control-flow logic, as those flags are read inside functions which are called from other functions, completely hiding the control flow inside flags and function calls. To follow the flow-logic, it is necessary to step inside every function and check how the conditional statements evaluate the flags and where the code executes after.

Is there any good pattern adressing such cases ? Is there some good concept to avoid this complexity ?

I intentionally ask that in general as this should be a problem occuring in multiple domains.

Aucun commentaire:

Enregistrer un commentaire