Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Velocity Template Language's set directive requires a variable on the left hand side. This doesn't work.

#set ( $entries.add("d") )

Even though I have no use for the return value of add("d"), I have to assign it to a variable.

#set ( $x = $entries.add("d") ) 

I want to communicate that the variable is necessary, but I have no intention of using it later. Is there a convention for naming variables that only exist to appease the compiler?

share|improve this question

closed as off topic by Mark Trapp Dec 1 '11 at 18:47

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

how about just using a comment – Gratzy Dec 1 '11 at 15:15
foo? [15 characters] – Konrad Morawski Dec 1 '11 at 15:15
I would call it code smell. – Joel Etherton Dec 1 '11 at 17:53
Hi Patrick, variable naming questions are off-topic here: for more information, check out Are “name that thing” questions on-topic? – user8 Dec 1 '11 at 18:48
@Mark Okay, thanks. FWIW, I think this question leans more toward the "proper term for a concept" than "naming suggestions for a class or a method." I'm looking for an idiomatic name that would be used in various languages and codebases, not a specific name for a single variable. – Patrick McElhaney Dec 1 '11 at 19:03
up vote 26 down vote accepted

I tend to use dummy for this kind of situation (a variable that I must have though I don't need to use).

share|improve this answer
I always use ignored. I would have added my own answer but I couldn't think of anything else to say about that. – John Buchanan Dec 1 '11 at 17:53
Besides dummy, I also use _ (some languages accept it), dump, junk, bhole (from black hole), useless, and some others names I don't recall right now. – PEdroArthur Dec 1 '11 at 18:04
+1 because after much searching, I discovered that by default, pylint ignores an unused variable named either "_" or "dummy". – Patrick McElhaney Dec 1 '11 at 23:24
And while searching for something else, found a mention of $dummy specifically in Velocity. – Patrick McElhaney Dec 2 '11 at 17:24

You should check and see if your language has a name specifically for this use - Python has _ that you should use for variables you intend to throw away.

share|improve this answer
Note that _ is the traditional name for this kind of variable in languages that provide pattern matching (ML, Haskell, scala, etc.) – barjak Dec 1 '11 at 15:28
@barjak Good to know - I've never used any of those languages, I thought it was a Python thing – Izkata Dec 1 '11 at 20:38

dummy, temp, trash, black_hole, garbage ... any one of these tells me I won't be using them for anything.

If I do use if for something, I always rename the variable though.

share|improve this answer
+1 for renaming it if you do use it later. – Spencer Rathbun Dec 1 '11 at 18:36
Thanks, but this doesn't answer the question. I can think up plenty of names that say "this is not important." I'm looking for a single, standard name. – Patrick McElhaney Dec 1 '11 at 21:09
Except for a few newer languages, most of them don't have such. Such standard does not exist, if you don't consider the ones that gotten the most votes in here as "standard". – Rook Dec 1 '11 at 22:25

You have plenty of good answers already, however I thought I'd toss one that's more directly related to velocity.

What is the add method returning? If it's null you can simply tell velocity to quietly reference it:


However if you are replacing a value, and it returns the old value (like Map.put does), then you would need to set it to a dummy variable of some sort, if it's a void method, then you shouldn't need the variable at all.

If you're adamant about not using a new variable you could do the following:

#if($entries.add("d")) #end

If you're using it often enough I'd create a macro for it, then use it throughout your templates. I don't see how useful that might be though, but at least you'd only need to comment it once...

share|improve this answer
Brilliant! The method returns true in this case ($entries is an ArrayList), but man, I wish that worked. – Patrick McElhaney Dec 1 '11 at 17:08
I was afraid that you were in fact referencing a list. I've edited the answer to denote a way that you could go about not using a dummy variable, but I'm not so sure if I'd use it... – Scott Dec 1 '11 at 17:55

I would give it a reasonable name and add a comment explaining that you are only assigning it to appease the compiler. I have seen cases where someone has used a variable name like unused and another developer has subsequently used that variable by that name and made an ugly mess of the code.

share|improve this answer
I like unused too. The only problem I have with it is the fact that I'm using it the moment I'm writing it :/ – Rook Dec 1 '11 at 16:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.