在程序中应该完全避免使用goto吗? [英] Should use of goto completely avoided in programs?

查看:89
本文介绍了在程序中应该完全避免使用goto吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序,用于从C源文件中删除评论

i ...

1.首先构建一个DFA

2.使用goto语句编写程序。


现在很容易使用goto和amp;来模拟DFA。我想这也是

效率。


所以在这里使用goto是什么?


thanx


Sumit

PUCSD

I wrote a program for removing comment from C source file for which
i...
1.first constructed a DFA
2.used goto statement to write a program.

now it was very easy to model DFA using goto & i suppose it was also
efficient.

so was the use of goto right here?

thanx

Sumit
PUCSD

推荐答案

SUMIT说:
SUMIT said:
我写了一个程序,用于从C源文件中删除评论
我...
1.首先构建了一个DFA
2.used goto编写程序的声明。

现在使用goto& amp;模拟DFA非常容易。我想它也很高效。

这里是否使用了goto?
I wrote a program for removing comment from C source file for which
i...
1.first constructed a DFA
2.used goto statement to write a program.

now it was very easy to model DFA using goto & i suppose it was also
efficient.

so was the use of goto right here?




如果它使程序更清晰阅读和维护比替代品,

是的。否则,没有。并且它的可能性很大。


DFA等状态机通常使用以下方式实现(在程序中使用b $ b $语言)构造如C'的开关(多路

选择)。在OOP中,您可能会使用更多的东西 - 呃 -

OO。 :-)


goto的问题在于它会使维护成为猪。


-

Richard Heathfield

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

电子邮件:rjh在上面的域名



If it made the program clearer to read and maintain than the alternatives,
yes. Otherwise, no. And the odds are good that it didn''t.

State machines such as DFAs are normally implemented (in procedural
languages, at least) using a construct such as C''s switch (multi-way
select). In OOP, you would probably do it using something a bit more - er -
OO. :-)

The problem with goto is that it tends to make maintenance a pig.

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




SUMIT写道:

SUMIT wrote:
我写了一个程序,用于从C源文件中删除评论
我...
1.首先构建了一个DFA
2.used goto语句来编写程序。

现在使用goto& amp;模拟DFA非常容易我想这也很有效。

这里是否使用了goto?

还不是

Sumit
PUCSD
I wrote a program for removing comment from C source file for which
i...
1.first constructed a DFA
2.used goto statement to write a program.

now it was very easy to model DFA using goto & i suppose it was also
efficient.

so was the use of goto right here?

thanx

Sumit
PUCSD




是否正确取决于以下答案

问题:


1.这是一次性的,快速肮脏的工作,再也不会被b $ b触及吗?


2。代码是否容易理解?没有写过代码?


3.代码是否可以轻松更新以反映任何可能的变化

DFA?


如果1的答案是否,那么2和3的答案都更好

是是;否则你需要重新评估你是如何使用gotos的。


Gotos本身并不是坏事,但你必须遵守纪律

in你如何使用它们,否则它们会导致维护问题。

你永远不应该替换一个结构化的构造(if-else,for,while,

do-while,switch )带goto。你永远不应该分成一个区块,

你应该只向前分支。在某些情况下,它们可能会干扰

与编译器优化。



Whether it was right or not depends on the answers to the following
questions:

1. Is this a one-off, quick-n-dirty job that''s never going to be
touched again?

2. Is the code easy to understand by someone who didn''t write it?

3. Can the code easily be updated to reflect any potential changes in
the DFA?

If the answer to 1 is "no", then the answers to both 2 and 3 had better
be "yes"; otherwise you need to re-evaluate how you are using gotos.

Gotos by themselves aren''t a bad thing, but you have to be disciplined
in how you use them, otherwise they can lead to maintenance headaches.
You should never replace a structured construct (if-else, for, while,
do-while, switch) with a goto. You should never branch into a block,
and you should branch forward only. In some cases they may interfere
with compiler optimizations.


On Tue,2005年9月6日13:54:49 +0000 (UTC),Richard Heathfield

< in ***** @ invalid.invalid>写道:
On Tue, 6 Sep 2005 13:54:49 +0000 (UTC), Richard Heathfield
<in*****@invalid.invalid> wrote:
SUMIT说:
SUMIT said:
我写了一个程序,用于从C源文件中删除评论
我...
1.首先构建了一个DFA
2.used goto语句来编写一个程序。
现在很容易使用goto和amp;来模拟DFA。我想这也很有效。

这里是否正在使用goto?
I wrote a program for removing comment from C source file for which
i...
1.first constructed a DFA
2.used goto statement to write a program.

now it was very easy to model DFA using goto & i suppose it was also
efficient.

so was the use of goto right here?



如果它使程序更清晰,可以阅读和维护比其他选择,
是的。否则,没有。并且很可能它没有。

诸如DFA之类的状态机通常使用C'开关等构造实现(至少使用程序语言) (多路选择)。在OOP中,你可能会使用更多的东西 - 呃 -
OO。 :-)

goto的问题是它往往会使维护成为猪。



If it made the program clearer to read and maintain than the alternatives,
yes. Otherwise, no. And the odds are good that it didn''t.

State machines such as DFAs are normally implemented (in procedural
languages, at least) using a construct such as C''s switch (multi-way
select). In OOP, you would probably do it using something a bit more - er -
OO. :-)

The problem with goto is that it tends to make maintenance a pig.






这篇关于在程序中应该完全避免使用goto吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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