Member-only story

Why do programmers like to use foo and bar?

Beck Moulton
4 min readSep 21, 2024

--

If you are new to programming, you may occasionally hear or see words like ‘foo’ and ‘bar’. What do they specifically mean? Why do programmers use them?

Programmers use “foo” and “bar” as common meta syntactic variables. These variables serve as placeholders in programming, replacing the actual variable names, and are typically modified, updated, or deleted later in the code.

The following article will delve into the meanings, origins, and usage of “foo” and “bar”, and explain why these words make you feel familiar.

01

Universal placeholders in programming

As mentioned earlier, “foo” and “bar” are commonly used placeholder variables in programming, with “foo” being the most common.

The term ‘meta grammar variables’ may seem difficult to understand, but in fact, all you need to know is that these are common placeholders commonly used in coding.

Why do programmers use placeholders like this when writing code?

Mainly because if variables do not need to have unique and exact names, they do not need to spend time carefully selecting a suitable name.

For example, if a programmer only needs to write a simple piece of code to demonstrate or showcase, the specific names of variables will have almost no impact. In this case, using “foo” and “bar” is completely acceptable.

--

--

Beck Moulton
Beck Moulton

Written by Beck Moulton

Focus on the back-end field, do actual combat technology sharing Buy me a Coffee if You Appreciate My Hard Work https://www.buymeacoffee.com/BeckMoulton

No responses yet