loading...

Why I Don't Use Foo/Bar/Baz

kiarathedev profile image Kiara Contreras ・1 min read

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.

Posted on by:

kiarathedev profile

Kiara Contreras

@kiarathedev

Web Developer / Cat Lover / Green Tea Witch / She/Her

Discussion

markdown guide
 

Hard same.

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

 

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.

 

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.

 

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.

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!

 

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

 

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