Does anyone else use this little idiom?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Feb 3 01:28:56 EST 2008
On Sun, 03 Feb 2008 15:08:34 +1100, Ben Finney wrote:
>> But I like using _ because it's only 1 character and communicates well
>> the idea "I don't care about this variable."
>
> Not to me. As you noted, '_' is easily ambiguous. Explicit is better
> than implicit; the name 'dummy' makes it much clearer.
Assuming you're not writing code like the following:
dummies = [Pacifier() for x in xrange(100)]
for dummy in dummies:
check_for_quality(dummy)
"dummy" as the name of a variable you don't care about is just a
convention, no different from "_" or "paris_hilton" or "shrubbery". In
fact, to me "dummy" implies that it holds a dummy value that will be
replaced later with the actual value needed.
If you want an explicit name, try a variation of "dontcare". Assuming
that you're an English speaker.
People seem to forget that "explicit" just means that there's a
convention that nearly everybody knows, and if you follow it, nearly
everybody will know what you mean. Often that convention is nothing more
than the meanings of words in whatever human language you're speaking,
but it's still a convention.
--
Steven
More information about the Python-list
mailing list