DEV Community

Kiara Contreras
Kiara Contreras

Posted on

Why I Don't Use Foo/Bar/Baz

As a beginner developer, I was always confused as to why others would use foo, bar, or baz. When I approached these words used in examples I assumed that they were pertinent to the code I was reading. I quickly learned that these names did not hold any weight and were often used in teaching examples as a placeholder for a better name.

While learning how to program, I've both picked up and discovered my own naming conventions. I've found that taking an extra moment to think up a clear name has been better for my understanding of the code presented, my peers reading my code, and future me, who doesn't vaguely remember what said code does.

Let's look at an example using foo/bar/baz:

foobarExample

How can this be improved for future programmers to read? If I take an extra moment to rename the variables then the function becomes easier to understand because each variable is pertinent to its data.

updatedExample

This is definitely a basic example, but all programmers start somewhere. I believe that naming examples with words or phrases can:

  • Help a person grasp a concept more easily when learning to program
  • Begin to teach them how to name data clearly
  • Create a better programmer from the start

Thanks for hearing me out. If you're interested, here's a cool Stackoverflow post about foo/bar/baz's history.

Top comments (7)

Collapse
 
quinncuatro profile image
Henry Quinn

Hard same.

I really thought that foo and bar were part of various languages' syntax when I was just starting out.

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€ • Edited

So a to improve the examples, there's a couple more things. Let's get the liniting out of the way because I have a compulsive nature so excuse me sorry 😣 I can't help myself.

  • Don't use let use const as there is no further assignment.
  • Semicolons everywhere or non at all.
  • Don't use double quotes and single quotes use one or the other.
  • function is not a pure function, takes no params so is probably unnecessary.

Okay on to the topic, the first example where foo, bar, baz is concerned, that is just bad mentoring. Foo bar baz are just debugging names (your dog's name, your own name, or just about anything you can see from your desk are aslo fair game), you might use them if you console.log alot and can't use execution breakpoints for whatever reason.

I do use foo, bar, but I didn't like baz so instead I use foo, bar, thunder, flash, hotdog.

Collapse
 
kiarathedev profile image
Kiara Contreras

Thanks for the formatting feedback.

On the topic, I’ve seen documentation/algorithm examples that use foo/bar/baz outside of debugging names so that’s where this post stems from.

Collapse
 
adam_cyclones profile image
Adam Crockett πŸŒ€

Introverted isn't it, almost as if the developer forgot that others would see this code. "Makes sense to me" he/she probably thought to themselves, and so Kiara you are absolutely justified in your post.

I have to say, it's not something I have thought much about, that's a bit frightening.

Also sorry If that was your code, I would have kept my mouth shut, it's rude to pick at silly little things like this.

Thread Thread
 
kiarathedev profile image
Kiara Contreras

Definitely! I've been trying to think about small topics that were daunting when I started and it's always interesting to think back. For some people, it's hard to empathize with not understanding basic concepts so I understand how this topic can be included in learning materials.

It was mine but it actually was helpful. I should be more careful about syntax if I'm going to post!

Collapse
 
anasidrissi profile image
anasidrissi • Edited

I liked ur post i have the same problem with this naming

Collapse
 
awwsmm profile image
Andrew (he/him)

Thankfully, it seems like the community is, on the whole, moving away from these "placeholder" names. Thanks for the article, Kiara!