
{"id":312,"date":"2015-10-26T02:06:12","date_gmt":"2015-10-26T01:06:12","guid":{"rendered":"http:\/\/serverdude.dk\/?p=312"},"modified":"2015-10-26T02:06:12","modified_gmt":"2015-10-26T01:06:12","slug":"9-bad-programming-habits-we-secretly-love","status":"publish","type":"post","link":"https:\/\/serverdude.dk\/?p=312","title":{"rendered":"9 bad programming habits we secretly love"},"content":{"rendered":"<p>Reading the article <a href=\"http:\/\/www.infoworld.com\/article\/2992566\/application-development\/9-bad-programming-habits-we-secretly-love.html\">9 bad programming habits we secretly love<\/a> I&#8217;m appalled that apparently this is considered the norm.<\/p>\n<p>While I have likely used all of these bad programming habits at one time or another, I&#8217;m pretty sure that these are mostly due to the fact that the programmer is a poor one. Thus writing the article and hoping to get cheered on, we&#8217;re apparently worshiping the mediocre or even poor workmanship.<\/p>\n<p>Depending upon where I reside in the hierarchy you should then either follow my advice or that of the article.<\/p>\n<h2>The habits:<\/h2>\n<h3>No.1: Using <code>goto<\/code><\/h3>\n<p>Using line numbers, you were bound to run out of valid line identifiers, thus you had to insert one line in essence telling &#8220;the code is to be continued on line xxx&#8221;, which made reading the code in its entirety really difficult.<\/p>\n<p>The article states that <em>a goto in a case statement will produce something that&#8217;s simpler to understand than a more properly structured list of cascading if-then-else blocks<\/em>. Well, swapping one bad idea for another really isn&#8217;t the way to argue. <a href=\"http:\/\/www.oodesign.com\/chain-of-responsibility-pattern.html\">Chain of Responsibility<\/a> would be the right abstraction in that case. The part that sometimes needs a goto is then a different method called by some of these handlers.<\/p>\n<h3>No. 2: Eschewing documentation<\/h3>\n<p>Documentation should state evergreen information on the entities. The intent of a class, function, field. In some rare cases it should provide sufficient insights as to why a specific approach is used over another.<\/p>\n<p>The code may be changing &#8211; and you&#8217;d likely then be violating the <a href=\"http:\/\/www.objectmentor.com\/resources\/articles\/ocp.pdf\">Open Closed Principle<\/a>, but that&#8217;s another story &#8211; rarely the intent of the code is changing at the same pace as the code itself.<\/p>\n<p>The function names suggested: <code>insertReservation<\/code> and <code>cancelReservation<\/code>are really poor names. Quite likely there would be an argument to these functions in the sort of a reservation object, and you would end up with having code as:<\/p>\n<pre>insertReservation(Reservation reservation)\r\ncancelReservation(Reservation reservation)<\/pre>\n<p>Which &#8211; when read out loud &#8211; really is stuttering and horrible. I prefer:<\/p>\n<pre>insert(Reservation reservation)\r\ncancel(Reservation reservation)<\/pre>\n<h3>No. 3: Jamming too much code on one line<\/h3>\n<p>Readability is at a premium, why would anyone write long lines of code? I know Java is basically a one dimensional source code language &#8211; hence the need for semicolons between statements. Why you cannot have a line wrapping string is then a bit odd, but that&#8217;s a different story.<\/p>\n<p>Yes, minified JavaScript loads faster, but leave minifying to minifiers.<\/p>\n<p>If you need to put things in a grouped environment, then either use functions or separate within functions with additional blank lines.<\/p>\n<p>The code is not getting longer &#8211; well, perhaps line-wise, but not really byte-wise or at least code-wise. The readability on the other hand goes up.<\/p>\n<h3>No. 4: Not declaring types<\/h3>\n<p>Well, that really depends upon your programming language. In a type safe language it does give you insight when reading the code, what the writer likely had in mind. You know that\u00c2\u00a0 <code>a + b<\/code> is supposed to be string concatenation and not an arithmetic sum if one of the arguments is a string. You know that <code>1\/2<\/code> is integer division and will<br \/>\nresult in 0 and not .5<\/p>\n<h3>No. 5: Yo-yo code<\/h3>\n<p>With the web a more frequent part of any development, there is a need for string to something else conversions, and sometimes back to strings again.  With JSON we have basic numbers, but no dates or timestamps, thus a string &lt;-&gt; x is needed.<\/p>\n<h3>No. 6: Writing your own data structures<\/h3>\n<p>Usually you really shouldn&#8217;t, not even for an anticipated performance improvement. But then &#8211; who knows &#8211; maybe you&#8217;re writing the next great data structure to be used for decades.<\/p>\n<h3>No. 7: Breaking out of loops in the middle<\/h3>\n<p>The reason for not breaking or returning at several different places is code readability &#8211; and thus maintainability. Odd thing is, then loop breaks are often used for &#8220;find first&#8221;. Java &#8211; being a bit slow on this &#8211; does not cater for this functionality, whereas Scala has <code>find(predicate)<\/code> doing exactly what is needed.<\/p>\n<h3>No. 8: Using short variable names (but i, x, and and make sense)<\/h3>\n<p>Definitely! Working with coordinates, math, physics you&#8217;d be less confusing using the nomenclature of those domains. Using <code>a<\/code> for an array and <code>l<\/code> for a list seems to be counter intuitive given habit No.4 &#8220;Not declaring types&#8221;. To be hones, I don&#8217;t care if it&#8217;s an array or a list &#8211; I care what it is: List of some sort of entities: Books, users, &#8230;<\/p>\n<h3>No. 9: Redefining operators and functions<\/h3>\n<p>This is only funny until you have to debug the 2nd and 3rd redefinition.  Use a mapping between whatever needs to be hacked using inverse logic and the sane world.<\/p>\n<h2>Summary<\/h2>\n<p>If you deliberately use any of the bad programming habits &#8211; with the exception of No.5, which has a few valid excuses &#8211; then my take is that you are a bad programmer. Luckily there are ways to improve &#8211; start by not doing these bad things. Follow up by not taking bad advice (mine included).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reading the article 9 bad programming habits we secretly love I&#8217;m appalled that apparently this is considered the norm. While I have likely used all of these bad programming habits at one time or another, I&#8217;m pretty sure that these are mostly due to the fact that the programmer is a poor one. Thus writing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-312","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=312"}],"version-history":[{"count":2,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/312\/revisions"}],"predecessor-version":[{"id":314,"href":"https:\/\/serverdude.dk\/index.php?rest_route=\/wp\/v2\/posts\/312\/revisions\/314"}],"wp:attachment":[{"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/serverdude.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}