Stop using Foo Bar!

Hi there,

I'm teaching myself RoR, and I've found myself on this forum a fair few
times when looking for solutions to problems.

I've also found many other sites with help forums and tutorials as well.

This may seem like a petulant request, but please for the love of all
things holy, can people stop using foo and bar in code demos and
tutorials please?

It may be because I'm very new to this and I have to work through every
step one by one, but I can't help being reminded of those IQ test
questions e.g:

"All Blobs are Zweezils, and some Zweezils are BoingBoings, does this
mean all Blobs are BoingsBoings?"

I'm guessing the nerdier among you felt the need to figure that one out.
But if I'd written:

"All RoR developers are nerds; some nerds are uncomfortable in social
situations. Does this mean all RoR developers are uncomfortable in
social situations?

I assume most of you made sense of that immediately and came up with the
answer 'no'.

Using Foo and Bar, just seems to add another level of mental processing
to go through before you can start grasping the concepts of what's being
explained.

I appreciate that sometimes, real world examples might make it more
complicated if the words/variable names being used seem to overlap with
what might be Ruby code (to a newbie at least).

Can I just ask for a little bit of imagination when giving examples
please?

(Sorry to come on here and rant in my first ever post, I just figured
this would be a good place to get it seen - I hope I'm not alone in my
frustration).

Cheers,

Jules.

Can I just ask for a little bit of imagination when giving examples
please?

No.

Longer version: programming is dealing with abstractions. If one want
to learn programming then it is
unavoidable.
Or maybe I am just spoiled by those math teachers who used a and b, x,
y and z instead of trying to
come up with something more imaginative.

Regards,
Rimantas

You can always use Voo, Doo, and Vlad. Metasyntactic variables are not
meant to be creative or original though. They are simply meant to represent
unknown variables. The common ones are Foo, Bar, and Baz.

Jules Copeland wrote:

Using Foo and Bar, just seems to add another level of mental processing
to go through before you can start grasping the concepts of what's being
explained.

I'm sure this is not the answer you're looking for, but I'm afraid
you're going to have to learn to live with foo, bar, baz and foobar.
These reference placeholders have been in use as long as I've been
programming computers. It's such an ingrained part of the programmer's
culture it will likely never disappear.

That being said. These placeholders are very often misused.

"They are commonly used to represent unknown values, typically when
describing a scenario where the purpose of the unknown values is
understood, but their precise values are arbitrary and unimportant." --
Ref: http://en.wikipedia.org/wiki/Foobar

What you are describing is a scenario where the unknown values may not
be understood, and their values are rational and important. In these
scenarios good tutorials should avoid arbitrary references placeholders
and use more descriptive examples.

Example:

def foo
  bar = 10
  baz = 5
  foobar = bar + baz
end

In such an example the meaning should be clear because the placeholders
are truly arbitrary and unimportant. Any attempt to assign meaning to
the variable severs no apparent purpose.

I just don't see the point in adding an extra layer of abstraction where
there doesn't need to be one...

Most RoR evangelists go on about the readability of the code, so why
spoil it by putting gibberish in?

If you're going to the effort of trying to explain something to someone,
why not make the explanation as clear as possible?

c.f. <http://tools.ietf.org/html/rfc3092>

What you are describing is a scenario where the unknown values may not
be understood, and their values are rational and important. In these
scenarios good tutorials should avoid arbitrary references placeholders
and use more descriptive examples.

Example:

def foo
  bar = 10
  baz = 5
  foobar = bar + baz
end

In such an example the meaning should be clear because the placeholders
are truly arbitrary and unimportant. Any attempt to assign meaning to
the variable severs no apparent purpose.

Very good point. I don't have a problem with them in those kind of very
trivial examples, but once things start getting more complex, the use of
foobar just makes it harder to understand.

I'm teaching myself RoR, and I've found myself on this forum a fair few
times when looking for solutions to problems.

I've also found many other sites with help forums and tutorials as well.

This may seem like a petulant request, but please for the love of all
things holy, can people stop using foo and bar in code demos and
tutorials please?

Yes, it's a petulant request. Welcome to programming. There's a culture and
a tradition here. You aren't going to change it. Foo and bar (and baz, and
quux -- see
http://www.catb.org/~esr/jargon/html/M/metasyntactic-variable.html for
more) are part of that culture tradition.

It may be because I'm very new to this and I have to work through every
step one by one

[...]

Yes, you're very new. When entering a new culture, try not to play the
"ugly American" and expect the culture to change and suit you. (Disclosure:
I am a US citizen and as liable to be labeled an "ugly American" as anyone
else.)

Using Foo and Bar, just seems to add another level of mental processing
to go through before you can start grasping the concepts of what's being
explained.

You need to learn the jargon when entering any field. When it comes to
programming, you need to understand bits, bytes, floating point number, a
million other things and, yes, foo and bar and friends.

I appreciate that sometimes, real world examples might make it more
complicated if the words/variable names being used seem to overlap with
what might be Ruby code (to a newbie at least).

Can I just ask for a little bit of imagination when giving examples
please?

No. The point of foo and bar, which you have so blithely missed, is to
avoid details that would distract from the meat of what is being discussed.
When you see something like:

module Foo
  def do_foo
    puts "Foo!"
  end
end

class Bar
  include Foo
  def do_foo
    puts "Bar!"
  end
end

...you can immediately tell that we're looking at an example of whether a
method in an included module is overridden by a method in the including
class or not (hint: it is). Those placeholders could be absolutely
anything, but using foo and bar make it clear that the names should not be
the focus of your attention.

(Sorry to come on here and rant in my first ever post, I just figured
this would be a good place to get it seen - I hope I'm not alone in my
frustration).

You may not be alone in your frustration, but you need to get over it.
Why do algebra examples typically use x, y, and z as variables? Culture and
tradition. I wouldn't expect that to change, ever, and you shouldn't expect
foo, bar, baz, etc. to change, either.

Cheers,
Jules.

--Greg
P.S. Sorry to be grumpy, but I now understand how many Parisians feel about
     most American tourists.

Jules Copeland wrote:

I just don't see the point in adding an extra layer of abstraction where
there doesn't need to be one...

I'd suggest picking another battle to fight. This one is arbitrary and
unimportant. It's not a battle you can win. You're focusing the blame
for bad tutorial examples in the wrong place anyway.

The use of foo as a variable placeholder is no difference than using x
in mathematics to represent a reference to an arbitrary value. There are
a lot of people that also have trouble with this abstraction and find
algebra difficult to grasp. That does not mean that math instructors
should stop using x, y and z as abstract placeholders to unknown values
in a equation.

Part of the problem with more ‘realistic’ variable names is that some people will fixate on the names and fail to notice the general principal. For example

def has_min_elements?(foo, bar)

foo.size >= bar

end

might be harder to read for someone new but

def bookshelf_has_at_least(bookshelf, number_of_books)

bookshelf.size > number_of_books

end

will have some people thinking about bookshelves and completely missing the fact that ‘bookshelf’ is an arbitrary name for an instance of an Array or Hash (possibly a String even).

I used to teach Prolog and the unlearning that had to take place after they wrote their first family tree program because the predicates had names like isa, parent and grandparent was a constant impediment. They understood the program very quickly but completely failed to understand Prolog. I ended up having to do search and replace on predicate and variable names to turn them into gibberish just to show them that the predicate and variable names had nothing to do with the how the program worked.

Learning means getting out of your comfort zone.

Besides Foo, Bar and Baz (along with xyzzy and plover) have a long and distinguished history.

Foo and Bar are the conceptual equivalent of using lorem ipsum when
designing web pages. They're obviously not real things and so don't
distract the user's attention away from the bigger picture.

I do agree with some people here who've pointed out that as soon as
variables hold something meaningful (eg inside a method) then you should
give them neaningful names, but that's not quite the same thing.

What i did find a little confusing with learning rails was the canonical
example of a blog that has_many posts, that has_many comments. Once
rest came along, i was learning that as well as ajax, i really wished
one of the example models wasn't called 'post'. I was seeing stuff like

link_to "Post", post_path(post), :method => :post

which is a bit confusing.

(this precise example may not make sense but you get the general idea)

Wow - I didn't realise this would be such an emotive topic!

Thanks for all your replies.

You all make good points. I didn't mean to come across as aggressive, so
apologies to all those who have come to the defence of your beloved
metasyntactic variables! (Thanks for teaching me a new piece of jargon
btw).

(On a related point - my friend just pointed me towards Why's Poignant
Guide to Ruby - just had a quick scan through... the examples in there
are awesome).

Jules Copeland wrote:

Hi there,

I'm teaching myself RoR, and I've found myself on this forum a fair few
times when looking for solutions to problems.

Hello, friend. Stay a while, and listen.
(Diablo I)

I've also found many other sites with help forums and tutorials as well.

This may seem like a petulant request, but please for the love of all
things holy, can people stop using foo and bar in code demos and
tutorials please?

I sense a soul in search of answers.
(Diablo I)

It may be because I'm very new to this and I have to work through every
step one by one, but I can't help being reminded of those IQ test
questions e.g:

"All Blobs are Zweezils, and some Zweezils are BoingBoings, does this
mean all Blobs are BoingsBoings?"

I'm guessing the nerdier among you felt the need to figure that one out.

Wrong - everybody figured that one out as soon as they read it.
(Me)

Using Foo and Bar, just seems to add another level of mental processing
to go through before you can start grasping the concepts of what's being
explained.

That's interesting; I just tweeted a link to a really, really
interesting article about programming and thinking:
http://the-programmers-stone.com/about/

Do read it all. I hope you find it enlightening.
Consider "Foo" and "Bar" to be like scrubbing the floor and painting the
fence in the movie "The Karate Kid". Reading them is tricky at first,
but when you get used to them, you have learned a skill, whether you
realize it or not.

Jules Copeland wrote:

Wow - I didn't realise this would be such an emotive topic!

Think of it this way, you've stepped into the middle of a new culture
with a strong tradition and history. There are unwritten and abstract
rules unknown to you.

It may seem perfectly reasonable to, for example, extend your left hand
to someone in greeting. This may, in certain cultures, invoke a very
different response than you might expect. Chance are, you'll be forgiven
the gesture being of foreign origin, but that does not change the
culture, nor the emotions behind the implied meaning of the gesture.

(On a related point - my friend just pointed me towards Why's Poignant
Guide to Ruby - just had a quick scan through... the examples in there
are awesome).

For a little more meat on this subject, and also server to illustrate
some of my earlier points about the common misuse of foo (and family)
see:

http://en.wikipedia.org/wiki/Alice_and_Bob

Jules Copeland wrote:

Hi there,

I'm teaching myself RoR, and I've found myself on this forum a fair few
times when looking for solutions to problems.

I've also found many other sites with help forums and tutorials as well.

This may seem like a petulant request, but please for the love of all
things holy, can people stop using foo and bar in code demos and
tutorials please?

It may be because I'm very new to this and I have to work through every
step one by one, but I can't help being reminded of those IQ test
questions e.g:

"All Blobs are Zweezils, and some Zweezils are BoingBoings, does this
mean all Blobs are BoingsBoings?"

I'm guessing the nerdier among you felt the need to figure that one out.
But if I'd written:

"All RoR developers are nerds; some nerds are uncomfortable in social
situations. Does this mean all RoR developers are uncomfortable in
social situations?

I assume most of you made sense of that immediately and came up with the
answer 'no'.

Using Foo and Bar, just seems to add another level of mental processing
to go through before you can start grasping the concepts of what's being
explained.

I appreciate that sometimes, real world examples might make it more
complicated if the words/variable names being used seem to overlap with
what might be Ruby code (to a newbie at least).

Can I just ask for a little bit of imagination when giving examples
please?

(Sorry to come on here and rant in my first ever post, I just figured
this would be a good place to get it seen - I hope I'm not alone in my
frustration).

Cheers,

Jules.

I actually agree with you, but I still like using it because Foobar is
an old Military term from Fubar which I used to use all the time. Anyone
wanna take a stab at what "Fubar" means? :wink:

I'll give you a hint.

____ Up Beyond All Recognition

Try having that one stuck in your head everytime you see an example.

~Jeremy

Not to mention popular spinoffs like FooCamp and BarCamp.

I think there is a difference between the case when the two variables
are genuinely independant as opposed to one where there is some
relationship between the two *and* that relationship is an inherent
part of the example being discussed (and where I doing maths I would
convey that by using x_a and x_b or x and x' or something like that).
I also wouldn't try and be needlessly obtuse ie

foos = Foo.all
bars = Bar.find ...

rather than

bar = Foo.all
baz = Bar.find ...

Fred

Frederick Cheung wrote:

I also wouldn't try and be needlessly obtuse ie

foos = Foo.all
bars = Bar.find ...

rather than

bar = Foo.all
baz = Bar.find ...

You're right. Read the article I linked to. It talks about consistency.
:wink:

Frederick Cheung wrote:

a lot of people that also have trouble with this abstraction and find
algebra difficult to grasp. That does not mean that math instructors
should stop using x, y and z as abstract placeholders to unknown values
in a equation.

I think there is a difference between the case when the two variables
are genuinely independant as opposed to one where there is some
relationship between the two *and* that relationship is an inherent
part of the example being discussed (and where I doing maths I would
convey that by using x_a and x_b or x and x' or something like that).

This is what I've been trying to say - thank you for putting it more
succinctly.

When the variables have some kind of relationship to each other, using
utterly arbitrary words really does detract from the example.

Seeing as a lot of RoR deals with data from a relational database, using
foo bar makes it much harder to understand - especially in the case of a
code snippet where you can't see the class declarations and relevant
relationships.

It's not April 1st yet, fix your clock.

-Kyle