该代码段看起来如何是伪代码?
我有这段代码:
for(iteration<string> it=name_list.iterator();it.hasNext();)
上面的代码合适的伪代码表示是什么?
I have this code:
for(iteration<string> it=name_list.iterator();it.hasNext();)
What would be a suitable pseudo-code representation for the above code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于伪代码应该更易于人类阅读,所以我只是选择类似的内容:
您不需要在伪代码中添加迭代器等实现细节,而应该简单地指定意图.而且我发现 Python 的编码风格非常适合这类事情。
您还应该使用比
it
更具描述性的名称。我假设这是针对迭代器的,但它绝对没有给出变量是什么的指示。这不仅是伪代码的目标,也是真实代码的目标。Since pseudo-code is meant to be more human-readable, I'd simply opt for something like:
You shouldn't have any need to put implementation details like iterators in your pseudo-code, rather you should simply specify intent. And I find the Python style of coding suits this sort of thing perfectly.
You should also use more descriptive names than
it
. I'm assuming that's for iterator but it gives absolutely no indication as to what the variable is. This is something you should aim for not just in pseudo-code but in real code as well.将真实代码变成伪代码的最简单方法就是把它搞砸。 :-) 哇哈哈!
这可能会变成
name_list.iterator 的每次迭代,因为
它也可能变成数百个其他迭代!
The easiest way to make real code into pseudocode is to screw it up. :-) mwahahaha!
That could turn into
for each iteration of name_list.iterator as it
It could turn into hundreds of others too!
“对于 name_list 中的每个项目”至少这可能是意图。这段代码本身只是一个无限循环,因为它从不移动迭代器
"For each item in name_list" at least that's probably the intention. This code on its own is just an infinite loop though because it never moves the iterator