I can see the point when talking to non programmers, but when you're at a whiteboard discussing a problem with some team members .. I would miss my foos and my bars. I think the prevalence of foo/bar is an example of the ability of most programmers to think abstractly.
Probably more of an issue if you're in the training arena.
I use them when demonstrating that any values of 'foo' and 'bar' will suffice, like "you can get the size of an object with sizeof(foo)." It's handy for getting people to understand the general concept and not just the particulars. For instance, if I'd said "you can get the size of an object with something like sizeof(int)", then it's almost guaranteed that someone would ask if that also works for floats.
对于全新的程序员,我不得不说术语 foo 和 bar 可能不知道。 我认为它们是特定于语言的东西(即 C),但在查看维基百科之后我现在知道它们只是抽象的占位符。 因此,如果您的受众中不知道其含义的人,那么其他事情就更清楚了。 另外,first_number 等告诉我们这些都是数字,无论它们如何呈现,而不是其他东西。
For totaly new programmer I have to say that terms foo and bar might not be known. I thought that they were something language specific (namely C), but after cheking Wikipedia I now know they are just abstract place holders. So if your audience consist of people who don't know meanings of them, something else is much clearer. Also first_number and so tells that those are numbers how ever they are presented and not something else.
唯一应该使用 Foo 和 Bar 的时候是当你谈论一些非常抽象的东西以至于添加上下文需要额外的讨论时。 那么 Foo 和 Bar 的可读性和创建的代码比 x、y 和 z 等替代方案更容易遵循。
I choose not to foo and bar whenever my audience is familiar enough with the concept at hand that it would prove a detriment to their understanding.
The only time Foo and Bar should be used is when you are talking about something so abstract that adding a context would require additional discussion. Then Foo and Bar are much more readable and created code that is more followable than the alternatives, like x, y and z.
I think it is due to mildly, or maybe not so mildly, sarcastic nature of many programmers. While many people have tried to place different meanings on foo/bar most , or at least many, of us think of "FUBAR", F**K Up Beyond All Recognition. Its a way for "experienced" people to make a snide comment about everyone else.
Because of this I never use it for non programmer and seldom use it even with experienced programmers. If I do use you can bet I am making a veiled reference to the subject at hand.
除了避免使用诸如 foo 和 foo 之类的无意义单词之外, 吧,我发现为具有相同关系的现实场景提供代码示例更为重要。 这确实有助于学习者正确理解主题并防止误解。 例如,如果我正在教授依赖注入并展示示例代码,其中 Car 类的实例被注入到 Driver 类中,那么没有人会感到困惑并认为“那么这意味着 Car 控制了 Driver ?”。
On top of avoiding nonsensical words like foo & bar, I've found it's much more important to provide code examples for real-world scenarios which have the same relationships. This really helps a learner to understand a topic properly and prevents misunderstandings. E.g., if I'm teaching about Dependency Injection and show example code where an instance of the Car class is injected into the Driver class, no one's going to get confused and think "So that means the Car controls the Driver then?".
I think there is another important reason for using foo and bar in examples. These names make it clear that you are not invoking any magic keywords. Whenever I am reading some documentation or code examples, I like the arbitrary parts of the example to be clearly distinguished from the necessary parts.
If you substituted the nonsense word for what it generically represents in the example code, you might end up with some names that look a lot like the keywords, classes, or methods you're trying to explain. The "my" prefix, as in myNumber, myFunction, is a good compromise that makes names stand out as being arbitrary.
我是编程新手,或多或少是自学的。 我在网上阅读了很多示例代码,一开始发现自己替换了 foo 和 bar &c。 具有更相关的名称,例如上面的第一个数字和第二个数字示例。
我现在更喜欢 x,y,z,i... 因为 foo 和 bar 似乎在我的脑海中激发了语言冲动,可以分散我对日常事务的注意力,而且我已经在某种程度上发展了容纳一大堆不同的东西的能力。我头脑中的变量并记住它们是什么。 但我仍然肯定建议在教别人时使用相关命名,尤其是向不编程但需要了解程序如何工作的人解释代码时。
I am new to programming, and more or less self taught. I read a lot of example code online and at the beginning found myself replacing foo and bar &c. with more relevant names, such as the firstnumber and secondnumber examples above.
I now prefer x,y,z,i... because foo and bar seem to spark linguistic impulses in my mind and can distract me from the routine, and I've developed, somewhat, the ability to hold a whole bunch of different variables in my head and remember what they are. But I would still definitely recommend using relevant naming when teaching someone else, especially when explaining code to someone that doesn't program but needs to understand how the program works.
public void foo() {
// Do some things
if (bar) {
throw new Exception(baz);
}
}
因为它模糊了你想要教的内容。
It strictly depends on what are you trying to teach. Sometimes, when showing a programming example, you have to declare a few things just for the snippet to be "complete", and those few things are not the core of what you are showing.
For example, if you want to show how to throw an exception, I believe it is ok to present a snippet like
public void foo() {
// Do some things
if (errorCondition) {
throw new Exception("Error message");
}
}
Since the point in it is showing exceptions, there is no point in caring about the method name, so foo is "legal" in this context, or at least for me.
What I would not accept (in this same example) would be
public void foo() {
// Do some things
if (bar) {
throw new Exception(baz);
}
}
发布评论
评论(10)
当与非程序员交谈时,我可以明白这一点,但是当你在白板上与一些团队成员讨论问题时..我会想念我的 foos 和 bar。 我认为 foo/bar 的流行是大多数程序员抽象思考能力的一个例子。
如果你在训练场上,这可能是一个更大的问题。
I can see the point when talking to non programmers, but when you're at a whiteboard discussing a problem with some team members .. I would miss my foos and my bars. I think the prevalence of foo/bar is an example of the ability of most programmers to think abstractly.
Probably more of an issue if you're in the training arena.
我有时会使用它们。 但前提是“真实”姓名不相关。
I use them sometimes. But only if a "real" name is not relevant.
我在演示“foo”和“bar”的任何值都足够时使用它们,例如“您可以使用 sizeof(foo) 获取对象的大小”。 它可以很方便地让人们理解一般概念而不仅仅是细节。 例如,如果我说“你可以使用 sizeof(int) 之类的方法获取对象的大小”,那么几乎可以肯定有人会问这是否也适用于浮点数。
I use them when demonstrating that any values of 'foo' and 'bar' will suffice, like "you can get the size of an object with sizeof(foo)." It's handy for getting people to understand the general concept and not just the particulars. For instance, if I'd said "you can get the size of an object with something like sizeof(int)", then it's almost guaranteed that someone would ask if that also works for floats.
对于全新的程序员,我不得不说术语 foo 和 bar 可能不知道。 我认为它们是特定于语言的东西(即 C),但在查看维基百科之后我现在知道它们只是抽象的占位符。
因此,如果您的受众中不知道其含义的人,那么其他事情就更清楚了。 另外,first_number 等告诉我们这些都是数字,无论它们如何呈现,而不是其他东西。
For totaly new programmer I have to say that terms foo and bar might not be known. I thought that they were something language specific (namely C), but after cheking Wikipedia I now know they are just abstract place holders.
So if your audience consist of people who don't know meanings of them, something else is much clearer. Also first_number and so tells that those are numbers how ever they are presented and not something else.
当我的听众足够熟悉手头的概念时,我选择不去 foo 和 bar ,因为这会损害他们的理解。
唯一应该使用 Foo 和 Bar 的时候是当你谈论一些非常抽象的东西以至于添加上下文需要额外的讨论时。 那么 Foo 和 Bar 的可读性和创建的代码比 x、y 和 z 等替代方案更容易遵循。
I choose not to foo and bar whenever my audience is familiar enough with the concept at hand that it would prove a detriment to their understanding.
The only time Foo and Bar should be used is when you are talking about something so abstract that adding a context would require additional discussion. Then Foo and Bar are much more readable and created code that is more followable than the alternatives, like x, y and z.
我认为这是由于许多程序员的温和,或者也许不那么温和的讽刺天性造成的。 虽然很多人都试图给 foo/bar 赋予不同的含义,但我们中的大多数人(至少是很多人)都会想到“FUBAR”,F**K 超出了所有人的认知。 这是“有经验的”人对其他人进行冷嘲热讽的一种方式。
因此,我从不将它用于非程序员,即使是经验丰富的程序员也很少使用它。 如果我确实使用了,你可以打赌我是在隐晦地提及当前的主题。
I think it is due to mildly, or maybe not so mildly, sarcastic nature of many programmers. While many people have tried to place different meanings on foo/bar most , or at least many, of us think of "FUBAR", F**K Up Beyond All Recognition. Its a way for "experienced" people to make a snide comment about everyone else.
Because of this I never use it for non programmer and seldom use it even with experienced programmers. If I do use you can bet I am making a veiled reference to the subject at hand.
除了避免使用诸如 foo 和 foo 之类的无意义单词之外, 吧,我发现为具有相同关系的现实场景提供代码示例更为重要。 这确实有助于学习者正确理解主题并防止误解。 例如,如果我正在教授依赖注入并展示示例代码,其中 Car 类的实例被注入到 Driver 类中,那么没有人会感到困惑并认为“那么这意味着 Car 控制了 Driver ?”。
On top of avoiding nonsensical words like foo & bar, I've found it's much more important to provide code examples for real-world scenarios which have the same relationships. This really helps a learner to understand a topic properly and prevents misunderstandings. E.g., if I'm teaching about Dependency Injection and show example code where an instance of the Car class is injected into the Driver class, no one's going to get confused and think "So that means the Car controls the Driver then?".
我认为在示例中使用
foo
和bar
还有一个重要原因。 这些名称清楚地表明您没有调用任何魔术关键字。 每当我阅读一些文档或代码示例时,我喜欢将示例中的任意部分与必要部分清楚地区分开来。如果您将示例代码中的无意义单词替换为它通常表示的内容,那么您最终可能会得到一些看起来很像您试图解释的关键字、类或方法的名称。 “my”前缀(如
myNumber
、myFunction
)是一个很好的折衷方案,可以使名称显得任意。I think there is another important reason for using
foo
andbar
in examples. These names make it clear that you are not invoking any magic keywords. Whenever I am reading some documentation or code examples, I like the arbitrary parts of the example to be clearly distinguished from the necessary parts.If you substituted the nonsense word for what it generically represents in the example code, you might end up with some names that look a lot like the keywords, classes, or methods you're trying to explain. The "my" prefix, as in
myNumber
,myFunction
, is a good compromise that makes names stand out as being arbitrary.我是编程新手,或多或少是自学的。 我在网上阅读了很多示例代码,一开始发现自己替换了 foo 和 bar &c。 具有更相关的名称,例如上面的第一个数字和第二个数字示例。
我现在更喜欢 x,y,z,i... 因为 foo 和 bar 似乎在我的脑海中激发了语言冲动,可以分散我对日常事务的注意力,而且我已经在某种程度上发展了容纳一大堆不同的东西的能力。我头脑中的变量并记住它们是什么。 但我仍然肯定建议在教别人时使用相关命名,尤其是向不编程但需要了解程序如何工作的人解释代码时。
I am new to programming, and more or less self taught. I read a lot of example code online and at the beginning found myself replacing foo and bar &c. with more relevant names, such as the firstnumber and secondnumber examples above.
I now prefer x,y,z,i... because foo and bar seem to spark linguistic impulses in my mind and can distract me from the routine, and I've developed, somewhat, the ability to hold a whole bunch of different variables in my head and remember what they are. But I would still definitely recommend using relevant naming when teaching someone else, especially when explaining code to someone that doesn't program but needs to understand how the program works.
这完全取决于你想教什么。 有时,在显示编程示例时,您必须声明一些内容才能使代码片段“完整”,而这些内容并不是您所显示内容的核心。
例如,如果你想展示如何抛出异常,我相信呈现这样的代码片段是可以的,
因为其中的要点是显示异常,所以关心方法名称是没有意义的,所以 foo 是“合法的”在这种情况下,或者至少对我来说。
我不接受的(在同一个例子中)是
因为它模糊了你想要教的内容。
It strictly depends on what are you trying to teach. Sometimes, when showing a programming example, you have to declare a few things just for the snippet to be "complete", and those few things are not the core of what you are showing.
For example, if you want to show how to throw an exception, I believe it is ok to present a snippet like
Since the point in it is showing exceptions, there is no point in caring about the method name, so foo is "legal" in this context, or at least for me.
What I would not accept (in this same example) would be
as it is obscuring what you are trying to teach.