恐怖!在有限状态机中使用goto语句? [英] Horror! Using goto statement in finite state machines?

查看:156
本文介绍了恐怖!在有限状态机中使用goto语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在钻研有限状态机,而且此时似乎

实现它们的最佳方式是通过强烈使用goto

声明。然而,每个人和他们的祖母都在不断地咒骂

goto声明,指责它是某种撒旦的产物。所以它好像b $ b似乎我们这里有泡菜。


事情是,起初认为似乎没有任何可行的

替代品更适合此任务。是的,可能结束

结果将是一个纠结的混乱,但据我所知,一组嵌套如果

和switch语句在这个问题上不会有太大改善。 br />

那么,您对此主题有何看法?是否在这个应用程序中使用goto语句这个应用程序确实是解决这个问题的最佳方法,或者它是不合理的,并且有一些我错过的天赐方法在?

提前致谢

Rui Maiel

-

使用KDE 3.5.6运行Kubuntu 6.10和为此感到自豪。

jabber:ru ******** @ jabber.org

I''ve been delving into finite state machines and at this time it seems that
the best way to implement them is through an intense use of the goto
statement. Yet, everyone plus their granmother is constantly cursing at the
goto statement, accusing it of being some sort of spawn of satan. So it
seems we have a pickle here.

The thing is, at first thought it seems that there aren''t any viable
alternatives which are better suited for this task. Yes, probably the end
result will be an entangled mess but as far as I know a set of nested if
and switch statements will not improve much on the subject.

So, what are your views on this subject? Is the use of goto statements in
this application really the best possible solution to this problem or is it
unjustified and there is some godsend method which I''m missing out on?
Thanks in advance
Rui Maiel
--
Running Kubuntu 6.10 with KDE 3.5.6 and proud of it.
jabber:ru********@jabber.org

推荐答案

Rui Maciel < ru ******** @ gmail.comwrites:
Rui Maciel <ru********@gmail.comwrites:

我一直在钻研有限状态机,此时似乎

实现它们的最佳方法是通过强烈使用goto

语句。然而,每个人和他们的祖母都在不断地咒骂

goto声明,指责它是某种撒旦的产物。所以它好像b $ b似乎我们这里有泡菜。
I''ve been delving into finite state machines and at this time it seems that
the best way to implement them is through an intense use of the goto
statement. Yet, everyone plus their granmother is constantly cursing at the
goto statement, accusing it of being some sort of spawn of satan. So it
seems we have a pickle here.



如何使用switch语句或函数指针数组?

-

Ben Pfaff
bl*@cs.stanford.edu
http://benpfaff.org


Rui Maciel说:
Rui Maciel said:

我一直在钻研有限状态机,此时好像实现它们的最好方法是通过大量使用

转到声明。
I''ve been delving into finite state machines and at this time it seems
that the best way to implement them is through an intense use of the
goto statement.



这并不让我感到惊讶。

It doesn''t surprise me.


然而,每个人和他们的祖母都在不断地/>
在goto语句中诅咒,指责它是某种产生

of satan。所以看来我们这里有泡菜。
Yet, everyone plus their granmother is constantly
cursing at the goto statement, accusing it of being some sort of spawn
of satan. So it seems we have a pickle here.



不要让他们让你失望。如果您认为goto是最好的方式,那么

然后使用goto。这就是我们所说的艰难学习方式,但至少

你会学到的。

Don''t let them put you off. If you think goto is the best way to go,
then use goto. It''s what we call learning the hard way, but at least
you''ll learn.


事情是,在首先想到似乎没有任何可行的替代品更适合这项任务。是的,可能

最终结果将是一个纠结的混乱,但据我所知,一组

嵌套if和switch语句在这个问题上不会有太大改善。
The thing is, at first thought it seems that there aren''t any viable
alternatives which are better suited for this task. Yes, probably the
end result will be an entangled mess but as far as I know a set of
nested if and switch statements will not improve much on the subject.



如果你认为交换机不会改进/很多/那么你已经同意

它们是什么改进了什么你已经说过的是最好的方式。

If you think switches won''t improve /much/, then you already agree that
they''re an improvement on what you have already said is "the best way".


那你对这个问题有什么看法?
So, what are your views on this subject?



你自相矛盾。

That you contradict yourself.


是否使用goto语句

在这个应用程序中真的是解决这个问题的最佳解决方案
Is the use of goto statements
in this application really the best possible solution to this problem



不,但如果这就是你想做的事,不要让我们阻止你。

No, but don''t let us stop you if that''s what you want to do.


或者它是不合理的,还有一些天赐之道的方法我错过了什么?b $ b错过了?
or is it unjustified and there is some godsend method which I''m
missing out on?



嗯,当然,总有正确的方法,但不要担心你的头脑。

。 br />

Well, there''s always the right way, of course, but don''t worry your head
about it.


提前致谢

Rui Maiel
Thanks in advance
Rui Maiel



我不是一个人对于拼写火焰,但你可能想多花一点时间来学习如何拼写自己的名字。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh位于上述域名, - www。

I''m not one for spelling flames, but you might want to put a little more
effort into learning how to spell your own name.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


文章< 45 ******* ***************@news.telepac.pt>,

Rui Maciel< ru ******** @ gmail.comwrote:
In article <45**********************@news.telepac.pt>,
Rui Maciel <ru********@gmail.comwrote:

>我一直在钻研有限状态机,而此时似乎实现它们的最佳方式是通过强烈使用goto
声明。然而,每个人和他们的祖母都在不断地咒骂
goto声明,指责它是某种撒旦的产物。所以它似乎我们这里有泡菜。
>I''ve been delving into finite state machines and at this time it seems that
the best way to implement them is through an intense use of the goto
statement. Yet, everyone plus their granmother is constantly cursing at the
goto statement, accusing it of being some sort of spawn of satan. So it
seems we have a pickle here.



你如何定义最佳?在这种背景下?你是在谈论

关于程序执行速度,关于程序写入的速度有多快,关于代码读取的容易程度,关于

如何轻松修改代码以添加或修改状态,

关于代码在运行时如何轻松调试?


实现机制各不相同根据状态是什么;

使用某种状态描述语言并不常见

通过转储出C的处理器传递然后编译

的代码。通过这种设置,对C代码阶段的可读性的担忧会大大减少 - 尽管

关注调试运行状态机的能力

可能仍然足以推动生成的代码,即人类相对可读的b $ b。


我不能说我有一个浩瀚的使用状态机的经验,

但是(和大多数程序员一样)我已经实现了一些,并且在一个大型复杂状态机上工作的团队已经支付了b $ b。到目前为止,

我已经实现的状态机都没有需要goto;

我做过的一些lex机器可能已经生成了goto'' s,

但是我没有实现州代码的项目。


我已经使用了while / switch / inline代码路由,我已经和/ switch / tables-and-function-pointer路线走了

,我已经走了

混合动力车;带有表格和函数指针的版本已经倾向于最令人满意的
,但是当采取行动时,状态会有所不同,那么状态会变得过于苛刻。

-

没有人有权通过要求经验证据来摧毁另一个人的信念。 - Ann Landers

How are you defining "best" in this context? Are you talking
about program execution speed, about how quickly the program
can be written, about how easily the code can be read, about
how easily the code can be modified to add or revise states,
about how easily the code can be debugged while it is running?

Implementation mechanisms vary according to what is being state''d;
it isn''t uncommon to use some kind of state description language
that is passed through a processor that dumps out C code that
is then compiled. With that kind of setup, concerns about the
readability of the C code phase become much reduced -- though
concerns about the ability to debug the running state machine
may still be sufficient to push towards generated code that
is relatively readable by humans.

I can''t say that I have a "vast" experience with state machines,
but (like most programmers) I''ve implemented a few, and have been
on a team that worked on a large complex state machine. So far,
none of the state machines I''ve implemented have required a goto;
some of the lex machines I''ve done might have generated goto''s,
but none of the projects for which I have implemented the state code.

I''ve gone the while/ switch/ inline code route, and I''ve gone the
while/ switch/ tables-and-function-pointer route, and I''ve gone
hybrids; the versions with tables and function pointers have tended
to be the most satisfying, but when the actions to be taken in
the states are too different then that can become too ackward.
--
"No one has the right to destroy another person''s belief by
demanding empirical evidence." -- Ann Landers


这篇关于恐怖!在有限状态机中使用goto语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆