One of the most puzzling things when learning to code is stumbling upon code examples where there’s variables, functions or classes named `Foo` and `Bar`. What the heck? What are these abstract, made up words doing to help people understand what the code is doing? I’d say, a whole lot of nothing. But before I start ranting, I realize I won’t “win” this battle. I do realize there’s a long history of its use and respect people’s use of it when taking all the options into consideration.
History of foo and bar: https://stackoverflow.com/questions/4868904/what-is-the-origin-of-foo-and-bar
It really blows my mind how pedantic some programmers can be, but then go and use Foo, Bar, Baz in their code examples. This is overcomplicating already abstract concepts and adding to potential confusion. I totally get their use for trivial code examples, but if we don’t write code in this way, why would we learn to read code in this way?
So a few reasons why it doesn’t make sense to use Foo, Bar, or Baz:
- They are completely made up. They don’t represent reality at all like the real data we use in our code does.
- They add to potential confusion.
- As teachers, we must have specific intent with our language and this does not fit in with that principal
But on the flip side there are some good arguments for using this made up terminology:
- Less distracting to code’s intent so you don’t get wrapped up looking at variable names
- When there’s no relationship between variables or functions, it can make more sense
So the takeaway here is to choose Foo and Bar when trying to draw attention to functionality and away from variable names. But as soon as functions or variables are doing something meaningful, or have a relationship, it may make more sense to name them as such, with specific intent in those names.
Leave a Reply