Re: Copy / Paste in software development
On Feb 15, 12:49 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
[...]
Well, _if_ (in the rare cases where appropriate) you keep the
messy FSA, then I think you have to deal with control flow
jumping all over the place whether you put in an integral
variable or not. I don't see any advantage to turning a
goto vertex_5;
into
next_vertex = 5;
Until you try to debug it. Being able to see what state you're
in just by reading a variable has a lot of advantages. It also
makes it clear that you are dealing with a state machine. If I
were writing the code by hand, I'd go one step further, and
insist that the state variable have class type, and all state
changes go through a member function, so that I could log them.
Of course, if I had to deal with a complicated state machine
today, I'd probably use some variant of the State pattern,
rather than a switch, at least in most environments. (An
implementation of the state pattern may require more memory than
just a switch---enough more to make a difference on really small
embedded processors.)
The one exception with regards to the goto might be if I were
using automatically generated code. As long as no one has to
understand or maintain the code, there's no problem with goto.
(This is basically the same argument you gave with regards to
transcribing a published algorithm. I sort of agree with your
argument there, too, as long as you stick with a literal
transcription.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34