{"id":392,"date":"2007-12-21T19:37:56","date_gmt":"2007-12-22T00:37:56","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/2007\/12\/21\/coding-malpractice\/"},"modified":"2007-12-21T19:37:56","modified_gmt":"2007-12-22T00:37:56","slug":"coding-malpractice","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2007\/12\/21\/coding-malpractice\/","title":{"rendered":"Coding Malpractice"},"content":{"rendered":"<p>I just wrote the following line of code. And it&#8217;s no mistake: it functions perfectly and does exactly what I wanted it to do:<\/p>\n<p><tt>$count += 0;<\/tt><\/p>\n<p>This is surely poor programming practice, essentially implicitly recasting a variable as an integer. But it&#8217;s simple and it works flawlessly. (The context: I run an SQL query saying <tt>SELECT SUM(votes)...<\/tt>, which makes the tabulation of all the entries MySQL&#8217;s problem, not mine. The one &#8216;flaw&#8217; is that the sum of no votes isn&#8217;t 0, but NULL. This becomes a very important distinction when you&#8217;re trying to display a number: &#8220;0 votes&#8221; isn&#8217;t the same as &#8221;&nbsp;votes.&#8221;)<\/p>\n<p>Since we all know that NULL + 0 = 0 (and, of course, integer + 0 = integer), adding 0 works flawlessly. Could I just convert it to an integer? Probably. But I haven&#8217;t done that stuff in a while, and I was far too lazy to pull up the documentation. And incrementing a variable by 0 is way more fun.<\/p>","protected":false},"excerpt":{"rendered":"<p>I just wrote the following line of code. And it&#8217;s no mistake: it functions perfectly and does exactly what I wanted it to do: $count += 0; This is surely poor programming practice, essentially implicitly recasting a variable as an &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2007\/12\/21\/coding-malpractice\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,11,13,22],"tags":[],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-computers","category-insanity","category-linux-tips","category-programming"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=392"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/392\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}