Meaningful Names

Bar the Foo, no one really cares about you.

I like good names for all things, even for test variables, even though you may not care what value they have. However, even if you don’t care what value it has, please think about people who will maintain it and tell them (by giving it a good name) what it supposed to represent (how about something like anyName, or anyEmail?).

3 Replies to “Meaningful Names”

  1. Using ‘foo’ says something very clear: it says that you don’t care what this value is.

    Many APIs make you jump around setting up stuff so that you can get at the bit you care about. If the API changes so that’s no longer necessary, the use of ‘foo’, etc, indicate that the test can have that section eliminated.

    This is all convention, of course, but it _is_ important to be able to signal to the maintainer that you really don’t care what something is.

  2. I understand that the use of foo is a convention that many people are used to (but I don’t believe all conventions are exactly good and shouldn’t be followed blindly). I find it very rare where you really don’t care about the value (especially with other APIs) because you still want your tests to represent how the real world works and what you intend to pass to something you use (e.g. aValidObject, anInvalidObject) therefore really does mean something implicitly.

    Since I prefer to leave behind as much information as I can for my fellow coders, foo (and the bar) have been banned from my list of words that really add little value. I prefer to make the “I don’t care what the value is” explicit, especially if it makes the code more readable.

  3. To the earlier reply, just the fact that you are explaining that ‘foo’ means “I don’t care and it will be ignored” already means it is not meaningful. Such a relationship, to me, is the show of a pride resides in all of our programmers that we want to show off that we are better than the rest of the crowd, and it is something that I have come to realize and trying to avoid by all cost. If you want to say that a variable is to be ignored (whether this is a good design or not is another topic), just name it “ignored” or “deprecated”).

Comments are closed.