state is how you behave to events ++ the first antibodhi law
it surprises me how often engineers confuse states with actions
i think this is the fundamental reification behind procedural statemess
and this mistake infects a lot of great projects with entropising debate
this error is the type of complexity growing belief that changes a simple state transition
o -------> o
to clever decompositions into state sequences
o -------> o -------> o -------> o -------> o -------> o
these clever motherfuckers see their steps and think
commit! commit!
bravely commiting each step a state transition
to databases
persistent files
and external protocols
marching along confidently
but the event handlers at each stage are not really considered
because it is still conceptually the handling of one event
so the alternative paths
(which have now multiplied with every added state)
are mentally excluded
you don't handle events in a state transition
you are handling an event during a state transition
so when they need to rollback at step 4
because a separate transaction has decreased an account below that needed for commit
it's from a bug tracker issued by qa
because they weren't thinking about the alternatives
because there shouldn't be
alternatives
there should be
one point only past which the transaction is committed
for every event
some events don't cause state transitions
that is fine
a system will not always learn to be somewhere new for every event
but there should never be many states linked together from one event
no state "sequences"
no steps committed
after every state transition
you should be able to fully handle all events consistently
this is how solid fault tolerant system are architected
as any antibuddhist would tell you
-+-+-
class State
{ public:
virtual ~State() {}
virtual bs::shared_ptr<State> push() = 0;
virtual bs::shared_ptr<State> pop() = 0;
};
class YangState;
class YinState : public State
{ public:
virtual bs::shared_ptr<State> push()
{
++yins_;
return NULL;
}
virtual bs::shared_ptr<State> pop()
{
--yins_;
if (yins_)
return NULL;
return new YangState;
}
private:
bs::integer<bs::positive> yins_;
};
class YangState : public State
{ public:
virtual bs::shared_ptr<State> push()
{ return new YinState; }
virtual bs::shared_ptr<State> pop()
{ throw bs::exception("pop unexpected"); }
};
class StateMachine
{ public:
void push()
{ transition(currentState_->push()); }
void pop()
{ transition(currentState_->pop()); }
private:
void transition(bs::shared_ptr<State> newState)
{
if (newState)
currentState_ = newState;
}
bs::shared_ptr<State> currentState_;
};
later addition of JungState or other events possible with the evolution of the system
lifetimes occur between events
always
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
galathaea: prankster, fablist, magician, liar