What do we mean by metasyntactic variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What do we mean by metasyntactic variable?

for eg the variables foo and bar what do they mean by saying that these variables are placeholders

18th Jun 2017, 7:23 AM
Mohit Krishnan
Mohit Krishnan - avatar
1 Answer
+ 3
It is part of the naming convention or rather naming style. Normally, you name your variables so that they mean something. This way, particularly if you are consistent, the code is logical and you don't have to scan it all to know what a given variable represents somewhere inside the program. However, there might be cases where you need just a variable with no particular meaning - this may be an iterator of a for loop for example - most often 'i' or 'x' and such. I even saw several codes where there was a method returning a two-tuple and since only its first element was needed, the assignment used an underline as the second one: a, _ = function_returning_a_2_tuple() That indicated that this second variable is not important, it just has to be there as a placeholder for the method not to raise an exception. I think similar case is with foo and bar. They do not have any particular meaning apart from their usual, low-importance indication :)
18th Jun 2017, 7:40 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar