{"id":2670,"date":"2022-05-19T00:12:00","date_gmt":"2022-05-19T05:12:00","guid":{"rendered":"https:\/\/www.becomebetterprogrammer.com\/?p=2670"},"modified":"2022-05-20T06:41:43","modified_gmt":"2022-05-20T11:41:43","slug":"why-do-programmers-use-foo-and-bar","status":"publish","type":"post","link":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/","title":{"rendered":"Why Do Programmers Use &#8220;foo&#8221; and &#8220;bar&#8221;? What Does It Mean?"},"content":{"rendered":"\n<p>If you\u2019re an up-and-coming programmer or have buddies who are programmers, you\u2019ve probably either seen or heard the terms \u2018foo\u2019 and \u2018bar\u2019 being tossed around every once in a while. What exactly do these terms mean, and why do programmers use them?<\/p>\n\n\n\n<p><strong>Programmers use \u201cfoo\u201d and \u201cbar\u201d as common metasyntactic variables. Metasyntactic variables are fundamentally placeholder variables that are utilized in coding. They are used in place of proper variables, and it is intended for them to be updated, changed, or deleted at a later stage of programming.<\/strong><\/p>\n\n\n\n<p>The remainder of this article will explore in further depth the terms \u201cfoo\u201d and \u201cbar,\u201d their origin and use, and will also explain why they might ring a bell in your mind. Keep reading to find out more.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/#%E2%80%9CFoo%E2%80%9D_and_%E2%80%9CBar%E2%80%9D_Are_Common_Metasyntactic_Variables\" >\u201cFoo\u201d and \u201cBar\u201d Are Common Metasyntactic Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/#The_Origin_of_%E2%80%9CFoobar%E2%80%9D\" >The Origin of \u201cFoobar\u201d<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/#%E2%80%9CFoobar%E2%80%9D_and_%E2%80%9CFUBAR%E2%80%9D\" >\u201cFoobar\u201d and \u201cFUBAR\u201d<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/#Why_%E2%80%9CFoo%E2%80%9D_and_%E2%80%9CBar%E2%80%9D_Are_Used\" >Why \u201cFoo\u201d and \u201cBar\u201d Are Used<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/#Final_Thoughts\" >Final Thoughts<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%80%9CFoo%E2%80%9D_and_%E2%80%9CBar%E2%80%9D_Are_Common_Metasyntactic_Variables\"><\/span><a id=\"post-2670-_a76nwmv4qgh6\"><\/a>\u201cFoo\u201d and \u201cBar\u201d Are Common Metasyntactic Variables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>As explained earlier, \u201cfoo\u201d and \u201cbar\u201d are common metasyntactic variables. In fact, \u201cfoo\u201d is the most common metasyntactic variable out of them all.<\/p>\n\n\n\n<p>Now, the words \u2018metasyntactic\u2019 variable might appear intimidating at first, but all you need to know for a basic understanding of what they mean is that they refer to terms that are common placeholders used while writing code.<\/p>\n\n\n\n<p>Why would programmers need to use placeholder terms while writing code? Well, a major part of it is that they don\u2019t have to spend time coining up a more accurate term for the variable if there is no need for the variable to have a unique and accurate name.<\/p>\n\n\n\n<p>This can be the case if, for example, a programmer needs to write up a short code simply for the purposes of showcasing or demonstration.<\/p>\n\n\n\n<p>The goal in this scenario would be to illustrate the code\u2019s core processes and show others how it works \u2013 the name of the variable involved itself would likely make little to no difference. Using \u201cfoo,\u201d \u201cbar,\u201d or both, in this case, would be perfectly acceptable.<\/p>\n\n\n\n<p>You may have come across \u201cfoo\u201d and \u201cbar\u201d &#8211; or both &#8211; used together very frequently in online coding tutorials. This frequent usage is because these tutorials want to emphasize the fact that the names of the variable, in this case, are unimportant, arbitrary, and subject to change. The code that follows is what deserves your focus and attention.<\/p>\n\n\n\n<p>Programmers can also use metasyntactic variables in the earlier stages of programming. By giving variables an arbitrary name, programmers can focus on writing the coding and optimizing the inner workings of the code instead of bothering with the naming of the variables.<\/p>\n\n\n\n<p>The names of the variables can be adapted to fit the program accordingly at a more appropriate time.<\/p>\n\n\n\n<p>\u201cFoo\u201d and \u201cbar\u201d can be used if the name of the variable they will hold is of little consequence or if there is simply not enough information available to the programmers to decide on a dedicated name for the variable. In this case, \u201cfoo\u201d and \u201cbar\u201d are quite convenient to default to.<\/p>\n\n\n\n<p>Other metasyntactic variables include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Baz<\/li><li>Qux<\/li><li>Quuz<\/li><li>Quux<\/li><li>Corge<\/li><\/ul>\n\n\n\n<p>There are also metasyntactic variables in other languages. \u201cHoge\u201d and \u201cfuga\u201d are two of the more popular ones in Japanese.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Origin_of_%E2%80%9CFoobar%E2%80%9D\"><\/span><a id=\"post-2670-_5qwx6773y4gl\"><\/a>The Origin of \u201cFoobar\u201d<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It appears that \u201cfoo\u201d and \u201cbar\u201d started gaining popularity in coding sometime around 1960-1970. The terms were popularized by MIT and DEC around this time.<\/p>\n\n\n\n<p>However, it should be noted that \u201cfoo\u201d had already been a somewhat known \u2018nonsense\u2019 word before this time, which might have made it an ideal candidate to be used as a placeholder word in coding.<\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/4868904\/what-is-the-origin-of-foo-and-bar\" target=\"_blank\" rel=\"noreferrer noopener\">This thread<\/a> on stack overflow will provide you with an in-depth, reference-based exploration into the origin of the terms \u201cfoo\u201d and \u201cbar\u201d if you wish to find out more.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E2%80%9CFoobar%E2%80%9D_and_%E2%80%9CFUBAR%E2%80%9D\"><\/span><a id=\"post-2670-_mp10467sxrut\"><\/a>\u201cFoobar\u201d and \u201cFUBAR\u201d<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>I mentioned earlier that when spelled together (as they often are), the words \u201cfoo\u201d and \u201cbar, or \u201cfoobar\u201d might ring a bell. Well, this is probably because of how similar they sound to the better-known term \u201cFUBAR.\u201d<\/p>\n\n\n\n<p>To be clear, they are entirely different. While many speculate that the words \u201cfoo\u201d and \u201cbar\u201d originated from \u201cFUBAR,\u201d the two mean different things.<\/p>\n\n\n\n<p>\u201cFUBAR\u201d is a term that was commonly used by the U.S military during the periods of the second world war. It stands for \u201cf***ed up beyond repair\u201d or \u201cf***ed up beyond recognition.\u201d In contrast, \u201cfoobar\u201d doesn\u2019t really mean anything without the context of being used while writing code.<\/p>\n\n\n\n<p>As for \u201cFUBAR\u201d being the origin of \u201cfoobar,\u201d there is definitely some evidence for this being the case. Especially when you consider how they are pronounced almost the same, and how \u201cfoo\u201d and \u201cbar\u201d are terms used together more often than not.<\/p>\n\n\n\n<p>Regardless of whether \u201cFUBAR\u201d was the origin of \u201cfoobar\u201d or not, it can be said with a high degree of certainty that the term \u201cFUBAR\u201d was at least somewhat responsible for promoting \u201cfoobar\u201d in terms of popularity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_%E2%80%9CFoo%E2%80%9D_and_%E2%80%9CBar%E2%80%9D_Are_Used\"><\/span><a id=\"post-2670-_bijvl3go1aa\"><\/a>Why \u201cFoo\u201d and \u201cBar\u201d Are Used<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The reason for this is quite simple, to be honest. It is because they just so happened to be picked up by programmers and coders. They gained a great deal of popularity as metasyntactic variables, and their use in coding skyrocketed.<\/p>\n\n\n\n<p>While numerous other metasyntactic terms could serve the purpose of being a placeholder just as well, it is the reality that using \u201cfoo\u201d and \u201cbar\u201d or \u201cfoobar\u201d is now a convention and standard practice in coding.<\/p>\n\n\n\n<p>Since these terms are placeholders, one of their primary requirements is to be easily recognizable as such by other programmers who happen to come across them in writing or hearing.<\/p>\n\n\n\n<p>\u201cFoo\u201d and \u201cbar\u201d are the most well-recognized among all other placeholder terms. \u201cFoobar\u201d as a term is so popular, in fact, that there is a dedicated audio player for windows named \u2018<a href=\"https:\/\/www.foobar2000.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">foobar2000<\/a>\u2019.<\/p>\n\n\n\n<p>Using lesser-known terms might end up causing confusion among readers because usually, in coding, variable names have to be accurate and suitable. Understanding code is hard enough as it is, right?<\/p>\n\n\n\n<p>For this reason, sticking to convention becomes important, and using \u201cfoo\u201d and \u201cbar\u201d becomes favorable over using the other, lesser-known terms that programmers might not have as easy a time picking up on.<\/p>\n\n\n\n<p>There are occasional use cases for other metasyntactic variables. If there are more than two variables that need placeholder names, it is common to follow up \u201cfoo\u201d and \u201cbar\u201d with \u201cbaz\u201d and \u201cqux.\u201d<\/p>\n\n\n\n<p>However, know that it is rarely the case that such a situation arises. Even rarer would be code that involves more than four placeholder variables.<\/p>\n\n\n\n<p>In such a situation, it would probably be best for the programmer to give the variables actual names instead of continuing to use placeholder variables, as the end code would become quite confusing to read and understand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span><a id=\"post-2670-_x9ao5s1ixn29\"><\/a>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u201cFoo\u201d and \u201cbar\u201d are two of the most commonly used metasyntactic variables. These are terms used as placeholder names for variables in coding and programming. They don\u2019t really mean anything as words and are just used in place of a more accurate name, generally for purposes of convenience.<\/p>\n\n\n\n<p>They were made popular during the 1960s and \u201970s by MIT and DEC, and the military term \u201cFUBAR,\u201d while meaning something entirely different, likely contributed greatly to their popularity.<\/p>\n\n\n\n<p>While there are a lot of other metasyntactic variables, \u201cfoo\u201d and \u201cbar\u201d are used most commonly as they are well-known and well-understood.<\/p>\n\n\n\n<p><strong>Was this article helpful?<\/strong><\/p>\n\n\n\n<p>Share your thoughts by replying on Twitter of <a href=\"https:\/\/twitter.com\/bbprogrammer\" target=\"_blank\" rel=\"noreferrer noopener\">Become A Better Programmer<\/a> or to <a href=\"https:\/\/twitter.com\/arealesramirez\" target=\"_blank\" rel=\"noreferrer noopener\">personal my Twitter account<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you\u2019re an up-and-coming programmer or have buddies who are programmers, you\u2019ve probably either seen or heard the terms \u2018foo\u2019 and \u2018bar\u2019 being tossed around every once in a while. What exactly do these terms mean, and why do programmers use them? Programmers use \u201cfoo\u201d and \u201cbar\u201d as common metasyntactic variables. Metasyntactic variables are fundamentally &#8230; <a title=\"Why Do Programmers Use &#8220;foo&#8221; and &#8220;bar&#8221;? What Does It Mean?\" class=\"read-more\" href=\"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/why-do-programmers-use-foo-and-bar\/\" aria-label=\"More on Why Do Programmers Use &#8220;foo&#8221; and &#8220;bar&#8221;? What Does It Mean?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2680,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[33],"tags":[],"class_list":["post-2670","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interesting-fun","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/2670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/comments?post=2670"}],"version-history":[{"count":4,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/2670\/revisions"}],"predecessor-version":[{"id":2726,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/posts\/2670\/revisions\/2726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media\/2680"}],"wp:attachment":[{"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/media?parent=2670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/categories?post=2670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.becomebetterprogrammer.com\/staging\/4563\/wp-json\/wp\/v2\/tags?post=2670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}