可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When you are using placeholder names when programming (not necessary variable names, but labels, mockup names, etc) and foo and bar is not enough, what do you use?
I guess baz is rather common as third name, and the lorem ipsum for longer texts. But then what?
回答1:
From Wikipedia:
A "standard list of metasyntactic variables used in syntax examples" is: foo, bar, baz, qux, quux, corge, uier, grault, garply, waldo, fred, plugh, thud, mos, henk, def.
回答2:
If an example is that complex, it would probably be easier to understand if you just used real variable names.
回答3:
For arbitrary names beyond bar, I've always gone with inky, pinky, blinky, and in exceptional cases, clyde.
回答4:
Here's the jargon file entry on metasyntactic variables.
回答5:
in France we use "toto", "tata", "titi" etc... instead of foo and bar... ("tyty" is rarely used)
回答6:
Names of swedish vegetables and fruits: gurka, tomat, banan. Bonus points if you have å, ä, or ö in the variable names. :-)
回答7:
foo, baz and bar are enough. For total confusion you can combine them into foobar, foobazbar, bazfoo, foofoo and so on.
回答8:
People at my work have a curious affinity for "monkey"
回答9:
I always like:
Because they are all a quick flick of one hand over all fingers, not far from your home position, and you can pronounce them (as opposed to zxcv and jkl which don't roll off the tongue quite as well :)
FWIW Common lisp has a package manager called asdf
回答10:
moo, cow, sheep, baa (in that order).
回答11:
It's probably a better habit to use names related to the problem, since this will aid communication.
But in cases where you are working in the abstract and really don't want the names to matter, there are lists of commonly-used metasyntactic variables available in the Jargon File (which lists several different progressions) or from Wikipedia (currently "foo, bar, baz, qux, quux, corge, uier, grault, garply, waldo, fred, plugh, thud, mos, henk, def").
Personally, I've never seen or used most of the unpronounceable words in those lists, but I have seen and prefer to use "foo, bar, baz, spam, fred, xyzzy."
Ultimately, any set of nonsense words should work, or any set of words that are nonsensical relative to the problem.
Some folks I know get really sick of foo, bar, et al., so an alternative is to use character names from TV shows. I frequently use "Fred, Barney, Wilma, Betty, Pebbles, BammBamm." This is particularly useful in abstract OO discussions, because "Fred is-a Flintstone" comes across pretty clearly.
回答12:
What's wrong with x
, y
, z
? Or a
, b
, c
?
回答13:
My favourites in German are “wilde” and “wutz”, in conjunction, which could be translated as “wild” and “piglet”. Also, there's “barfoos”, which, when spoken, sounds like “barfuß”, German for “barefoot”.
回答14:
I've also seen fee, fie, foe, fum.
回答15:
In Expert C Programming: Deep Secrets, Peter van der Linden used vegetables.
回答16:
回答17:
After foo, bar, baz and qux, which are the only canonical ones I can remember, I tend to use "META_SYNTACTIC_VARIABLE_1
", "META_SYNTACTIC_VARIABLE_2
", or just "$VAR1", "$VAR2" and so on.
回答18:
Pick a theme and use it.
Or use CPAN's ACME::MetaSyntactic to generate them for you. Lots of themes out of the box.
回答19:
回答20:
When writing code examples in Stack Overflow, I prefer using the "My" prefix; that is
- MyClass
- MyInstance
- MyEnumerator
- MySingleton
You get the idea. The adventage of this approach is that everyone knows what you are talking about without going into the details too much or distracting the attention from the topic.
(P.S. normally I hate the My prefix, like in "My Computer" or MySQL but I think it fits this scenario)
回答21:
I often go to blah
after foo
and bar
. I usually stop there.
回答22:
I often use "aap", "noot", "mies", from the "Leesplankje van Hoogeveen" (The page is in Dutch only, but I'll try to explain it. It's a board with simple words and pictures for teaching children to read and more importantly all the different vowels Dutch has. The last version of the board contains 18 vowels, most of them consist of different combinations of the 'vowel letters'. I'm not sure if it's seriously used in education, but it's IMHO a great piece of Dutch cultural history)
回答23:
If you find you need more names beyond baz, it probably means the mockup is getting too complicated and these names will actually make it more difficult to follow the example code. I'd just rename the symbols to use meaningful names.
(I'm not even considering the case where the throw-away code is becoming production code with all the foos and bars in it. I'm sure it never ever happens. Or else.)
Finally, not exactly conventionals yet, but here's my Turkish contributions: hede, hodo, budu & zart.
回答24:
In Italy, Disney characters are faves:
Pippo, Paperino, Topolino, (resp. Goofy, Donald, Mickey). Italy is, or was, the second country in Disney Popularity after the USA.
回答25:
I typically use single-letter placeholder variable names, and strings like "This is a button" or "Here is some text" / "here is more of it" for UI stuff.
回答26:
I use the Greek alphabet, but I rarely go past delta.