{"id":434,"date":"2020-02-04T15:51:17","date_gmt":"2020-02-04T15:51:17","guid":{"rendered":"https:\/\/kalkus.dev\/?p=434"},"modified":"2023-08-24T23:31:38","modified_gmt":"2023-08-24T23:31:38","slug":"the-naming-problem-in-programming","status":"publish","type":"post","link":"https:\/\/kalkus.dev\/blog\/2020\/02\/04\/the-naming-problem-in-programming\/","title":{"rendered":"The naming problem in programming"},"content":{"rendered":"\n<p><strong>Reading source code is more difficult than writing it.<\/strong> Inherently. Everybody who worked with a legacy system and needed to understand the authors\u2019 intent knows what I mean. Browsing through thousands of lines of function definitions, variables and figuring out what\u2019s the point is a daunting task.<\/p>\n\n\n\n<p>But why, actually?<\/p>\n\n\n\n<p><strong>Is reading a recipe difficult?<\/strong><\/p>\n\n\n\n<p><strong>Is it more difficult than writing it?<\/strong><\/p>\n\n\n\n<p><strong>Is reading a hundred years old recipe more difficult than understanding thirty days old recipe?<\/strong><\/p>\n\n\n\n<p>I don\u2019t think so.<\/p>\n\n\n\n<p>Why then reading source code gets more difficult as the code matures? What can be the reason for <a href=\"https:\/\/en.wikipedia.org\/wiki\/Software_rot\">software decay<\/a> and common hatred towards legacy systems?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"870\" src=\"https:\/\/kalkus.dev\/wp-content\/uploads\/2020\/02\/4408196113_d2d7db2635_k-1024x870.jpg\" alt=\"\" class=\"wp-image-436\" srcset=\"https:\/\/kalkus.dev\/blog\/wp-content\/uploads\/2020\/02\/4408196113_d2d7db2635_k-1024x870.jpg 1024w, https:\/\/kalkus.dev\/blog\/wp-content\/uploads\/2020\/02\/4408196113_d2d7db2635_k-300x255.jpg 300w, https:\/\/kalkus.dev\/blog\/wp-content\/uploads\/2020\/02\/4408196113_d2d7db2635_k-768x653.jpg 768w, https:\/\/kalkus.dev\/blog\/wp-content\/uploads\/2020\/02\/4408196113_d2d7db2635_k-1536x1305.jpg 1536w, https:\/\/kalkus.dev\/blog\/wp-content\/uploads\/2020\/02\/4408196113_d2d7db2635_k.jpg 1996w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let us think of the action of reading source code. What do we do when we try to understand the flow of the computer program?<\/p>\n\n\n\n<p>We are a bit like computers, but less effective. We go through the code and read the variables and functions. Because we are not as fast as machines we can\u2019t remember the value of each variable and we are unable to memorize the body of each function or subroutine. Our \u201cunderstanding\u201d is based on approximation. We read the name of the variable and try to guess its usage, its meaning. We read the name of a function and without reading its body we try to figure out what the function can do.<\/p>\n\n\n\n<p>It\u2019s exactly the same as in the real world. When we read about \u201ca carrot\u201d in the recipe we imagine a carrot. We can understand the concept of carrot without receiving a lengthy list of details about the carrot, such as its genetic code, mass, temperature, color and so on. <\/p>\n\n\n\n<p>But source code \u2013 even with the entire effort of object-oriented paradigm \u2013 is not like the real world.<\/p>\n\n\n\n<p>In the real world we have a huge, but a limited amount of words in our vocabularies. <strong>Natural language is processed by human brains in a completely different manner than source code by the compiler. For example \u201ca chair\u201d to a human being is not a particular chair but an idea of a chair.<\/strong> In most cases, we don\u2019t need detailed definitions to process natural language. On the contrary &#8211; in rare cases like the law we have big problems with the definitions.<\/p>\n\n\n\n<p>A very good example illustrating what would happen to the natural language if we process it as literally as computers process the source code is this video:<\/p>\n\n\n\n<iframe loading=\"lazy\" width=\"100%\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/cDA3_5982h8\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\"><\/iframe>\n\n\n\n<p>Let\u2019s go back to the process of reading source code by software engineers. We take the name (of function or variable) and guess. As long as the code is \u201cclean\u201d and not old enough to match our instinctive understanding of the definition our guess is somehow correct. In this situation, the process of reading is smooth and painless.<\/p>\n\n\n\n<p>The issues pop up when we can\u2019t guess properly.<\/p>\n\n\n\n<p> But the real issue is far greater. It\u2019s one of the fundamental problems of software development. Partly it\u2019s described by a <a href=\"https:\/\/martinfowler.com\/bliki\/TwoHardThings.html\">quote by Phil Karlton <\/a> <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>There are only two hard things in Computer Science: cache invalidation and naming things <\/p><cite>Phil Karlton<\/cite><\/blockquote>\n\n\n\n<p>I mean naming things.<\/p>\n\n\n\n<p>Naming things is the point of incompatibility between the world of humans and computers. <strong>In the real world, where the language is processed by human minds, which are able to process ideas, classes of objects we rarely invent new words. In the realm of a computer program, we constantly do it.<\/strong><\/p>\n\n\n\n<p>What happens when we invent a new word in a natural language? We learn it. There comes the new word \u201ccomputer\u201d and all the people learn that it\u2019s a kind of computing machine. But it doesn\u2019t matter if\u2019s MacBook Pro or new Dell XPS or ENIAC or PC. We don\u2019t have a new word describing computers slightly differently in every company or even the company\u2019s department.<\/p>\n\n\n\n<p>But in the software world, we do. \u201cUser\u201d means something different in every single program written so far. In one it\u2019s just user name and surname. In other, it\u2019s also the date of birth. In other, it\u2019s only sex and nickname.<\/p>\n\n\n\n<p><strong>We simply can\u2019t name anything properly in a computer program.<\/strong> Every construct within code does not match the real-world meaning of the world. <\/p>\n\n\n\n<p>We can be too vague \u2013 let\u2019s say naming the\nuser \u201cuser\u201d, or too precise \u201cuserWithNameAndSurnameAndSexAndDateOfBirth\u201d.\nAlmost never we will be able to fully express the object by its name. That\u2019s\nwhy reading source code is so difficult. The words, the names of variables and\nfunctions never mean what we believe they mean. We always need to go to\ndefinition and check. Every time we check we learn the new language of a\nparticular software project. Learning thousands of new words is difficult.\nTherefore reading source code is difficult\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reading source code is more difficult than writing it. Inherently. Everybody who worked with a legacy system and needed to understand the authors\u2019 intent knows what I mean. Browsing through thousands of lines of function definitions, variables and figuring out what\u2019s the point is a daunting task. But why, actually? Is reading a recipe difficult? [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":437,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[202,74],"tags":[13,86,89,87,88],"_links":{"self":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts\/434"}],"collection":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/comments?post=434"}],"version-history":[{"count":4,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts\/434\/revisions"}],"predecessor-version":[{"id":458,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/posts\/434\/revisions\/458"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/media\/437"}],"wp:attachment":[{"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/media?parent=434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/categories?post=434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kalkus.dev\/blog\/wp-json\/wp\/v2\/tags?post=434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}