Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Functional > state is how yo...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 2814 of 2841
Post > Topic >>

state is how you behave to events ++ the first antibodhi law

by galathaea <galathaea@[EMAIL PROTECTED] > Apr 16, 2008 at 10:59 PM

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




 4 Posts in Topic:
state is how you behave to events ++ the first antibodhi law
galathaea <galathaea@[  2008-04-16 22:59:28 
Re: state is how you behave to events ++ the first antibodhi law
Michael Press <rubrum@  2008-04-17 21:16:42 
Re: state is how you behave to events ++ the first antibodhi law
galathaea <galathaea@[  2008-04-20 14:15:49 
Re: state is how you behave to events ++ the first antibodhi law
galathaea <galathaea@[  2008-04-24 12:56:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:55:51 CDT 2008.