+ 1

Please explain the use of variable names "foo" and "bar"

Where does the termology "bar" and "foo" come from and how should it be used?

20th Dec 2016, 9:16 PM
3TW3
3TW3 - avatar
3 odpowiedzi
+ 6
It is a kind of programming tradition to use foo and bar as example function names (not really as variable names), similar to how "Hello World" is a tradition for the 1st program. I'm not sure where it originated but I suspect it is a twist on FUBAR (f***ed up beyond any repair). It is quite difficult to come up with sensible names for explanary functions like this, so foo and bar is quite handy. Then the next function in the tradition is baz .... and I have no idea why!
20th Dec 2016, 9:42 PM
Ettienne Gilbert
Ettienne Gilbert - avatar
+ 7
Foo and bar are simply arbitrary names for methods, classes, variables, etc. for when showing examples of programming syntax. They came from the word "fubar", an acronym for "effed up beyond all recognition". Yes, I'm serious. :P I have no idea why it became a universal thing.
20th Dec 2016, 9:45 PM
Tamra
Tamra - avatar
+ 1
Other than the reference to fubar. The functions foo() and bar() were used in most examples in the original "The C programming language", (The white book) by Kernighan and Richie. This book may have also started the "Hello world" as your first application. Hello world requires: 1 getting computer access (A big deal back in the mid 70's) 2 Learning how to create the source code (text editing) 3 Learning the steps to compile, link, and execute the application.
2nd Feb 2017, 2:06 AM
Dean Hayes
Dean Hayes - avatar