{"id":127,"date":"2006-04-28T13:10:12","date_gmt":"2006-04-28T20:10:12","guid":{"rendered":"http:\/\/www.red-sweater.com\/blog\/127\/whats-in-a-name"},"modified":"2006-04-28T13:22:09","modified_gmt":"2006-04-28T20:22:09","slug":"whats-in-a-name","status":"publish","type":"post","link":"https:\/\/redsweater.com\/blog\/127\/whats-in-a-name","title":{"rendered":"What&#8217;s in a Name?"},"content":{"rendered":"<p>I recently wrote about <a href=\"http:\/\/www.red-sweater.com\/blog\/125\/easy-programming\">Easy Programming<\/a>, my pseudo-methodology for &#8220;keeping going&#8221; in the face of difficult or tedious tasks. Since then, I&#8217;ve observed an aspect of my workflow that, while seemingly among the easiest of tasks, can be the most limiting to my productivity. What is this devastating conundrum? The challenge of naming code.<\/p>\n<p>\nI must have a christening hang-up. I get all cold-footed when the time comes to name a class, source file, method or function. Even variables! There&#8217;s a lot of pressure to come up with a name that is both instantly descriptive of the concept being represented, while also compatible with the prevailing code style, easy to pronounce, type, etc.\n<\/p>\n<p>\nCould it be that the most mundane task, giving names to the commodities we trade in, could be the <em>hardest<\/em> aspect of programming?\n<\/p>\n<p>\nIn light of my recent thinking on Easy Programming, I was inclined to think that the best solution is to just forge ahead. Don&#8217;t let myself get caught up in such antics. If I can&#8217;t think of a class name within 5 minutes, just call it <em>something<\/em> and get on with the show. After all, after everything is working, I can always rename it if I feel strongly about it. I was getting happy with this conclusion when Jonathan Wight of <a href=\"http:\/\/www.toxicsoftware.com\/blog\/\">Toxic Software<\/a> made a statement that tipped my thinking in the other direction:\n<\/p>\n<blockquote><p>\n&#8220;Generally if I can&#8217;t think of a name for a class it means that when i come to refactor the code that the class wasn&#8217;t well thought-out in the first place.&#8221;\n<\/p><\/blockquote>\n<p>\nWell, shucks. That sounds downright obvious now that I&#8217;ve heard somebody else say it.\n<\/p>\n<p>\n<a href=\"http:\/\/www.urbanape.com\/\">Zachery Bir<\/a> pointed out that such thinking is common in OOP circles. A bad name is often identified as a <a href=\"http:\/\/xp.c2.com\/CodeSmell.html\">code smell<\/a> &#8211; something that stands out in code as a sign of potential lurking problems. An article on <a href=\"http:\/\/c2.com\/cgi\/wiki?UsingGoodNamingToDetectBadCode\">good naming<\/a> supports exactly what Jonathan was getting at &#8211; that a badly named entity begs for refactoring.\n<\/p>\n<p>\nSo the dilemma becomes this: how do I keep my job easy, and name things correctly, and avoid spending an eternity doing it? My conclusion is that naming is important enough that it deserves a good length of consideration. Don&#8217;t be afraid to give yourself an hour or more! Do other stuff and let it sit in the back of your mind. You&#8217;re not wasting time. What you&#8217;re doing is designing on autopilot. When you think of the right name, it will serve as a specification for what you need to do &#8211; and specifications lead to easy programming. If you can&#8217;t deduce the right answer yourself, seek help from coworkers or the web. The articles on the <a href=\"http:\/\/c2.com\/cgi\/wiki\">C2 Wiki<\/a>, including those cited above and <a href=\"http:\/\/c2.com\/cgi\/wiki?MeaningfulName\">this one<\/a> on &#8220;meaningful names&#8221; go into detail about some techniques that might help you settle on the right name. There&#8217;s gotta be a right name for the class. What does it do? What should it do?\n<\/p>\n<p>\nSometimes you simply won&#8217;t be able to figure it out. A programming defeat, and it stings! At last it may be in your best interest to follow my first instinct: <em>simply forge ahead<\/em>. If you know you can get the job done and fix it later, your time may be better spent on <em>future refactoring<\/em> than on present-day moping around, trying to come up with the perfect name. Use your failure as a exploratory design experiment. It&#8217;s OK, you failed. We all do it. But whatever you do, don&#8217;t waste your time trying to come up with some &#8220;almost appropriate&#8221; name for your mistake. Don&#8217;t <em>fake success<\/em> by giving it some prestigious name that blends into the background. Name it SmadoodieCracker, or GodDamnImASuckyProgrammer, or something equally delightful. Better yet, pick a standard template and name all of your cop-out classes using this scheme: SuckyClass001, etc. Now you can do a global search for your smelly names.\n<\/p>\n<p>\nMany programmers will feel hesitant to adopt such a practice. Your self-esteem is not fully developed, and you fear that coworkers will see what a fraud you are. Surely your boss will decide that you&#8217;re not senior developer material after all. And here we thought you were an infallible genius! This all may be true on a sucky team, but on a good team they&#8217;ll appreciate your candidness. And when browsing the sources to SmadoodieCracker, should inspiration strike and present a clear vision of what the class should do, they won&#8217;t think twice about overhauling your ugly mess. You owe them a beer, now.\n<\/p>\n<p>\nOther people fixing your code? The easiest programming of all!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently wrote about Easy Programming, my pseudo-methodology for &#8220;keeping going&#8221; in the face of difficult or tedious tasks. Since then, I&#8217;ve observed an aspect of my workflow that, while seemingly among the easiest of tasks, can be the most limiting to my productivity. What is this devastating conundrum? The challenge of naming code. I [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,15],"tags":[],"class_list":["post-127","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-programming"],"_links":{"self":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":0,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"wp:attachment":[{"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redsweater.com\/blog\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}