0%

Foo & Bar

  1. “Foo” and “bar” as metasyntactic variables were popularised by MIT and DEC, the first references are in work on LISP and PDP-1 and Project MAC from 1964 onwards.

  2. Many of these people were in MIT’s Tech Model Railroad Club, where we find the first documented use of “foo” in tech circles in 1959 (and a variant in 1958).

  3. Both “foo” and “bar” (and even “baz”) were well known in popular culture, especially from Smokey Stover and Pogo comics, which will have been read by many TMRC members.

  4. Also, it seems likely the military FUBAR(F*cked Up Beyond All Repair) contributed to their popularity.

编程里面的foo和bar就是我们小时候写作文里面的小明和小红。写作文的时候,当然情节最重要,花时间去想角色的名字太麻烦了,就干脆叫小明小红好了。

维基百科上的解释

原文:

The terms foobar, foo, bar, baz and qux are sometimes used as placeholder names (also referred to as metasyntactic variables) in computer programming or computer-related documentation.[1] They have been used to name entities such as variables, functions, and commands whose purpose is unimportant and serve only to demonstrate a concept. The words themselves have no meaning in this usage. Foobar is sometimes used alone; foo, bar, and baz are sometimes used in that order, when multiple entities are needed.

译文:

术语foobar, foo, bar, baz 和qux经常在计算机编程或计算机相关的文档中被用作占位符的名字。当变量,函数,或命令本身不太重要的时候,foobar, foo,bar, baz 和qux就被用来充当这些实体的名字,这样做的目的仅仅是阐述一个概念,说明一个想法。这些术语本身相对于使用的场景来说没有任何意义。Foobar经常被单独使用;而当需要多个实体举例的时候,foo,bar,和baz则经常被按顺序使用。

Code Sample From Google

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private static final String ACTION_FOO = "org.ipcreator.ui.apps.contact.service.action.FOO";
private static final String ACTION_BAZ = "org.ipcreator.ui.apps.contact.service.action.BAZ";

/**
* Handle action Foo in the provided background thread with the provided
* parameters.
*/
private void handleActionFoo(String param1, String param2) {
// TODO: Handle action Foo
throw new UnsupportedOperationException("Not yet implemented");
}

/**
* Handle action Baz in the provided background thread with the provided
* parameters.
*/
private void handleActionBaz(String param1, String param2) {
// TODO: Handle action Baz
throw new UnsupportedOperationException("Not yet implemented");
}

foobar是计算机程序领域里的术语炒作,并无实际用途和参考意义。 在计算机程序设计与计算机技术的相关文档中,术语foobar是一个常见的无名氏化名,常被作为“伪变量”使用。

单词“foobar”或分离的“foo”与“bar”常出现于程序设计的案例中,如同Hello World程序一样,它们常被用于向学习者介绍某种程序语言。
“foo”常被作为函数/方法的名称,而“bar”则常被用作变量名。
下面是一段通过“foo”和“bar”来演示如何在Java、C及C++中连接两个字符串的实例程序:

1
2
3
4
5
//Java Code
String foo = "Hello, ";
String bar = "World";
System.out.println(foo + bar);
//Hello, World is printed to the screen by printing foo and bar
1
2
3
4
5
6
7
8
9
10
11
// C code

#include <stdio.h>
int main()
{
char foo[] = "Hello,";
char bar[] = "World!";
printf("%s %s\n", foo, bar);

return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
// C++ code

#include <iostream>
using namespace std;

int main()
{
char foo[] = "Hello,";
char bar[] = "World!";
cout << foo << " " << bar << endl;

return 0;
}

Reference

[1]编程中Foo, Bar 到底什么意思?
[2]Foobar
[3]What is the origin of foo and bar? [closed] [4]foo和bar词源

欢迎关注我的其它发布渠道