foo、bar究竟是什么意思

在学习编程语言的过程当中,尤为使用的是英文的书籍,咱们常常发现一些foo、bar、baz之类的名字,要么是变量的名字,要么是文件的名字。。。深究起来彻底不明因此。这究竟是什么意思呢?编程

示例

下面是《C++17 STL Cookbook》这本书的一些用例:编程语言

//foo用作类名
class foo {
public:
    static std::string &standard_string() {
        static std::string s{"some standard string"};
        return s;
    }
};

还有:ide

//用做文件名
path p {"testdir/foobar.txt"};

一样其余语言里也有这种状况,《The Go Programming Language》这本书使用了大量此类名字:函数

f, err = os.Open("foo.txt") // 用做文件名
//用作字符串
fmt.Println(Equal([]string{"foo"}, []string{"bar"}))

解释

那这些单词传达给咱们的意思是什么呢?实际上这些东西跟咱们中文里的张3、李4、王五这类词属于一类,表示当前命名“可有可无”,不影响当前概念的表达。学习

其余资料

维基百科里有比较专业的解释:spa

The terms foobar (/ˈfuːbɑːr/), or foo and others are 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 exact identity is unimportant and serve only to demonstrate a concept.

直译过来就是:code

foobar或者 foo等诸如此类的措辞在计算机编程或计算机相关文档中被用做占位符名字(也称为元语法变量)。它们一般被用来命名一些变量、函数或命令等此类实体,而这些实体一般不重要,并且仅仅用来演示一个概念。

请关注个人公众号哦。
clipboard.pngip

相关文章
相关标签/搜索