Gianni Mariani wrote:
[SNIP]
I can see the seething sincerity in that apology.
That is what they used to say when they are asked how will they spend
1000billions out of 700 and keep the balance of the budget...
Hawaii is a nice place. Have a drink for me, I won't be there.
You quitter!
(What should one drink there?)
I hope this is a joke .... he says, quivering in blinding fury, as he
reaches back for a counter to snipe arrogantly and relentlessly at the
cowering fool. .... sorry, got carried away.
It depends on the reader.
... here is one legit reason for
There are alternatives.
Of course. And IMHO they are better.
enums are not allways the best way to solve the problem.
Well, enum labels are "sort of global". So unless they are hidden inside
the scope of a class...
I don't know if you remember or came across, one of my philosphies of
good design is to keep the threshold for creating a new class to a
minimum.
My philosophy for good design is to not write a single character more code
than necessary. The art is to find that balance. Because another rule
comes in as well: if its definition is not exactly like the one for int, do
not use an int - you need a class.
I have done this in the past.
replaced the enum:
enum States
{
start_state,
finish_state,
some_other_state,
};
I would not use an enum to identify states of a state machine. That creates
strong coupling between the states. And those sould be independent as much
as possible, so that only those states know about each other which need to.
In this case the enum must know about all possible cases. It is not
necessarily bad, but it collects unrelated information into one place. It
strongly couples non-coherent concepts.
IMO in a state machine the Context needs to know its starting state. That
state needs to know the states it uses and so fort. The only place where I
think such information can or should be together is a sort of factory, which
is able to create/retrieve those state objects.
But that leads to far way. There are many different kinds of state
machines, some with pretty much fixed state-space while others might need to
change frequently.
with this:
class State;
namespace Machine
{
extern State start;
extern State finish;
extern State some_other;
};
inline bool IsSameState( const State & a, const State & b )
{
return (&a) == (&b);
}
In here I think you are better off comparing the type_id of those states.
Your function name indicates "is this the same state", and not "is this the
same object".
But in case of such a setup it makes much
Like I said above.
I am not really sure what did you say above. Using a class type (which has
to be defined by the user of the library) gives a lot of flexibility for a
small price. Of course - OTOH - the scenario I have described is very rare.
It is even more rare that the argument you need to pass through
transparently is an enum. So IMO it is not worth to change the language
because of it - or even to discuss it too much.
State machines: I - time to time - start to think about the ultimate state
machine implementation. But so far I bailed out, I think because I have not
seen enough real state machines from different problem domains to really see
the best way(s). And my feeling that this is a non-trivial problem is
backed up by the fact that several state-machine code generators exist. And
I am yet to see a code generator, which has no (serious) limitations and
does not sell itself by taking away the responsibility from programmers to
look at a very complex and frustrating problem. Lex et. al. is a bit
exception, but only as long as you do not need a runtime extensible grammar.