Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To foo bar, or not to foo bar: that is the question

This was something originally discussed during a presentation given by Charles Brian Quinn of the Big Nerd Ranch at acts_as_conference. He was discussing what he had learned from instructing a Ruby on Rails Bootcamp to many people both new to programming and new to Rails.

One particular slide that stood out was along the lines of never using foo and bar as examples when trying to teach someone to program. His reasoning was very simple.

Which is easier to understand?

baz = foo + bar

or

answer = first_number + second_number

It's happened many times myself when explaining something and I immediately jump to the go to foo bar placeholders but then realize my mistake and make the example make a lot more sense by using a real world scenario.

This is especially applicable when trying to teach someone who has had no programming exposure and you end up needing explain foo and bar before explaining what you're actually trying to teach.

However, using foo and bar for experienced programmers seems OK, though I personally think, along with Charles, that it's something that needs to change.

A quick SO search for "foo" returns over 20 pages of results with foo being used in more ways that I can comprehend. And in some cases where I'm reading a question on a particular language and I'm doing so to help understand that language better. If applicable variable names are used instead of foo and bar, it makes it much easier to understand and interpret the problem. So for seasoned developers, the construct seems a bit flawed as well.

Is this a habit that will ever be able to be kicked? Why do you choose to foo bar or to not foo bar?

like image 877
mwilliams Avatar asked Oct 24 '08 17:10

mwilliams


3 Answers

It strictly depends on what are you trying to teach. Sometimes, when showing a programming example, you have to declare a few things just for the snippet to be "complete", and those few things are not the core of what you are showing.

For example, if you want to show how to throw an exception, I believe it is ok to present a snippet like

public void foo() { 

   // Do some things

   if (errorCondition) {
      throw new Exception("Error message");
   }

}

Since the point in it is showing exceptions, there is no point in caring about the method name, so foo is "legal" in this context, or at least for me.

What I would not accept (in this same example) would be

public void foo() { 

   // Do some things

   if (bar) {
      throw new Exception(baz);
   }

}

as it is obscuring what you are trying to teach.

like image 199
Santiago Palladino Avatar answered Oct 18 '22 18:10

Santiago Palladino


I can see the point when talking to non programmers, but when you're at a whiteboard discussing a problem with some team members .. I would miss my foos and my bars. I think the prevalence of foo/bar is an example of the ability of most programmers to think abstractly.

Probably more of an issue if you're in the training arena.

like image 17
Niniki Avatar answered Oct 18 '22 19:10

Niniki


I use them sometimes. But only if a "real" name is not relevant.

like image 7
Toon Krijthe Avatar answered Oct 18 '22 19:10

Toon Krijthe