Foobar
foobar是電腦程式領域裏的术语,並無實際用途和參考意義。在计算机程序设计与计算机技术的相关文档中,术语foobar是一个常见的无名氏化名,常被作为“伪变量(英语:metasyntactic variable)”使用。
歷史
从技术上讲,“foobar”很可能在1960年代至1970年代初通过迪吉多的系统手册传播开来。另一种说法是,“foobar”可能来源于电子学中反转的foo信号();这是因为如果一个数字信号是低电平有效(即负压或零电压代表“1”),那么在信号标记上方一般会标有一根水平横线,而横线的英文即为“bar”。在《新黑客辞典(英语:Jargon File)》中,还提到“foo”可能早于“FUBAR”出现。[1]
在大约1930年至1952年之间,foo出现在比尔·霍尔曼(英语:Bill Holman (cartoonist))的漫画《Smokey Stover(英语:Smokey Stover)》中,比尔·霍尔曼说他之所以使用这个词,是因为在旧金山唐人街的一个中国玉雕雕像的底部看到了这个词,据称它象征着“好运”。[2]这可能与汉字“福”有关,“福”有时被翻译为“'foo”。[3]
例子
单词“foobar”或分离的“foo”与“bar”常出现于程序设计的案例中,如同Hello World程序一样,它们常被用于向学习者介绍某种程序语言。
“foo”“bar”常被作为函数/方法的名称或变量名。
下面是一段通过“foo”和“bar”来演示如何在Java、C及C++中连接两个字符串的实例程序:
//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
// C code #include <stdio.h> int main() { char foo[] = "Hello,"; char bar[] = "World!"; printf("%s %s\n", foo, bar); return 0; }
// C++ code #include <iostream> #include <string> using namespace std; int main() { string foo = "Hello,"; string bar = "World!"; cout << foo << " " << bar << endl; return 0; }
# Python code foo = "Hello," bar = "World!" print(foo + bar)
參見
- 无名氏
- FUBAR
- foobar2000
參考文獻
外部連接
查看维基词典中的词条「foobar」。
- The Jargon File entry on foobar(页面存档备份,存于互联网档案馆)
- RFC 3092 - Origin and usage of foobar
- Foobar2000 is an advanced audio player for the Windows platform
- RFC 1639 - FTP Operation Over Big Address Records (FOOBAR)