后藤真的像人们说的那么糟糕吗?

发布于 2024-10-09 18:28:50 字数 548 浏览 0 评论 0原文

可能的重复:
GOTO 仍然被认为有害吗?

最近我一直在阅读 K& 的《C 编程语言》。 R。我对 C 不太了解,但我了解一点 Java,在第 65 页(第二版)上,作者谈论了 Goto 以及它几乎总是毫无根据的。 最近我一直在编写一个游戏,其中计算机必须表现出某种原始水平的人工智能,我在其中用 Java 编写了很多 for、while 和 if 来模拟某种智能。尽管它很原始,但它有四个深度嵌入的“for 循环”,到处都是 if 语句,到最后我不知道在哪里放置中断,并且在打破一些循环的同时仍然循环其他循环,这使得我的游戏无法玩。最终,在巨大的压力下,我整理了它。

我的问题是:后藤有多糟糕?

如果我的游戏中有一个 goto(Java 并没有真正提供),我就不会浪费那么多时间摆弄换行符和括号。后藤真的有那么糟糕吗?他们为何如此被人憎恨?

Possible Duplicate:
GOTO still considered harmful?

Recently I've been reading "The C Programming Language" by K&R. I don't know much C, but I know a bit of Java, and on page page 65 (2nd ed.) the writers talk about Goto and how it is almost always unwarrented.
Recently I've been writing a game, where the computer must show some primitive level of AI, where I wrote lots of for, whiles, and ifs in Java to emulate some sort of intelligence. As primitive as it was, it there were four-deep embedded "for loops" with if statements all over the place, and by the end I lost track of where to put the breaks and was breaking some loops while still looping through others making my game unplayable. Eventually, after much stress I sorted it.

My questiuon is: How bad is Goto?

If I had a goto in my game (Java doesnt really provide one) I wouldn't have wasted so much time fiddling with breaks and brackets. Is Goto really so bad? Why are they so hated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小…红帽 2024-10-16 18:28:50

我认为,代码中的 goto 语句越多,可读性就越差

more goto statements in your code less readable would be your code, my opinion

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文