关于计算机语言中foo bar的意思

  记得在学习某些计算机编程语言时,例如像C/C++ 、Java 、Ruby等时都会碰到类似foo、bar或是foobar之类的词,它们大多数都是作为变量名、函数名出现的;可问题是为什么要选择这几个词呢,它们到底有什么意思?

  google了一下,发现了这些词的一些来历,现解释如下:

1:来自维基百科(http://zh.wikipedia.org/wiki/Foobar

计算机程序设计与计算机技术的相关文档中,术语foobar是一个常见的无名氏化名,常被作为“伪变量”使用。

从技术上讲,“foobar”很可能在1960年代1970年代初通过迪吉多的系统手册传播开来。另一种说法是,“foobar”可能来源于电子学中反转的foo信号(\bar{q});这是因为如果一个数字信号是低电平有效(即负压或零电压代表“1”),那么在信号标记上方一般会标有一根水平横线,而横线的英文即为“bar”。在《新黑客辞典》中,还提到“foo”可能早于“FUBAR”出现。

单词“foobar”或分离的“foo”与“bar”常出现于程序设计的案例中,如同Hello World程序一样,它们常被用于向学习者介绍某种程序语言。

“foo”常被作为函数/方法的名称,而“bar”则常被用作变量名。

2:来自《黑客词典》

foo/foo/

1. interj. Term of disgust.

2. [very common] Used very generally as a sample name for absolutely anything, esp. programs and files (esp. scratch files).

3. First on the standard list of metasyntactic variables used in syntax examples. See also barbazquxquuxgarplywaldofredplughxyzzythud.

When ‘foo’ is used in connection with ‘bar’ it has generally traced to the WWII-era Army slang acronym FUBAR (‘Fucked Up Beyond All Repair’ or ‘Fucked Up Beyond All Recognition’), later modified to foobar. Early versions of the Jargon File interpreted this change as a post-war bowdlerization, but it it now seems more likely that FUBAR was itself a derivative of ‘foo’ perhaps influenced by Germanfurchtbar (terrible) — ‘foobar’ may actually have been the original form.

For, it seems, the word ‘foo’ itself had an immediate prewar history in comic strips and cartoons. The earliest documented uses were in the Smokey Stover comic strip published from about 1930 to about 1952. Bill Holman, the author of the strip, filled it with odd jokes and personal contrivances, including other nonsense phrases such as “Notary Sojac” and “1506 nix nix”. The word “foo” frequently appeared on license plates of cars, in nonsense sayings in the background of some frames (such as “He who foos last foos best” or “Many smoke but foo men chew”), and Holman had Smokey say “Where there's foo, there's fire”.

According to the Warner Brothers Cartoon Companion Holman claimed to have found the word “foo” on the bottom of a Chinese figurine. This is plausible; Chinese statuettes often have apotropaic inscriptions, and this one was almost certainly the Mandarin Chinese word fu (sometimes transliterated foo), which can mean “happiness” or “prosperity” when spoken with the rising tone (the lion-dog guardians flanking the steps of many Chinese restaurants are properly called “fu dogs”). English speakers' reception of Holman's ‘foo’ nonsense word was undoubtedly influenced by Yiddish ‘feh’ and English ‘fooey’ and ‘fool’.

Holman's strip featured a firetruck called the Foomobile that rode on two wheels. The comic strip was tremendously popular in the late 1930s, and legend has it that a manufacturer in Indiana even produced an operable version of Holman's Foomobile. According to the Encyclopedia of American Comics, ‘Foo’ fever swept the U.S., finding its way into popular songs and generating over 500 ‘Foo Clubs.’ The fad left ‘foo’ references embedded in popular culture (including a couple of appearances in Warner Brothers cartoons of 1938-39; notably in Robert Clampett's “Daffy Doc” of 1938, in which a very early version of Daffy Duck holds up a sign saying “SILENCE IS FOO!”) When the fad faded, the origin of “foo” was forgotten.

One place “foo” is known to have remained live is in the U.S. military during the WWII years. In 1944-45, the term ‘foo fighters’ was in use by radar operators for the kind of mysterious or spurious trace that would later be called a UFO (the older term resurfaced in popular American usage in 1995 via the name of one of the better grunge-rock bands). Because informants connected the term directly to the Smokey Stover strip, the folk etymology that connects it to French “feu” (fire) can be gently dismissed.

The U.S. and British militaries frequently swapped slang terms during the war (see kluge and kludge for another important example) Period sources reported that ‘FOO’ became a semi-legendary subject of WWII British-army graffiti more or less equivalent to the American Kilroy. Where British troops went, the graffito “FOO was here” or something similar showed up. Several slang dictionaries aver that FOO probably came from Forward Observation Officer, but this (like the contemporaneous “FUBAR”) was probably a backronym . Forty years later, Paul Dickson's excellent book “Words” (Dell, 1982, ISBN 0-440-52260-7) traced “Foo” to an unspecified British naval magazine in 1946, quoting as follows: “Mr. Foo is a mysterious Second World War product, gifted with bitter omniscience and sarcasm.

Earlier versions of this entry suggested the possibility that hacker usage actually sprang from FOO, Lampoons and Parody, the title of a comic book first issued in September 1958, a joint project of Charles and Robert Crumb. Though Robert Crumb (then in his mid-teens) later became one of the most important and influential artists in underground comics, this venture was hardly a success; indeed, the brothers later burned most of the existing copies in disgust. The title FOO was featured in large letters on the front cover. However, very few copies of this comic actually circulated, and students of Crumb's oeuvrehave established that this title was a reference to the earlier Smokey Stover comics. The Crumbs may also have been influenced by a short-lived Canadian parody magazine named ‘Foo’ published in 1951-52.

An old-time member reports that in the 1959 Dictionary of the TMRC Language, compiled at TMRC, there was an entry that went something like this:

总的来说,foo bar foobar就是类似与我们在写程序时经常使用的i、j、k之类的变量,没有什么特定的含义,更多的只是一种约定,或者说习惯。

Steven Meng

2014.4.17

 

 

posted @ 2013-04-17 20:22  StevenMeng  阅读(1607)  评论(0编辑  收藏  举报