{"id":4394,"date":"2014-03-30T10:28:41","date_gmt":"2014-03-30T10:28:41","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/passing-a-boolean-to-a-function-instead-of-creating-two-functions-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:42:27","modified_gmt":"2022-08-30T15:42:27","slug":"passing-a-boolean-to-a-function-instead-of-creating-two-functions-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/passing-a-boolean-to-a-function-instead-of-creating-two-functions-collection-of-common-programming-errors\/","title":{"rendered":"Passing a boolean to a function instead of creating two functions-Collection of common programming errors"},"content":{"rendered":"<p>I would say this is a <strong>BIG<\/strong> no-no due to the following reasons :<\/p>\n<p><strong>Readability<\/strong> : There is only a very minor difference between the two keywords <code>setVisible()<\/code> and <code>setInvisible()<\/code> and its easy to mis-read while scrolling through 100s of lines of code.<\/p>\n<p><strong>Semantics<\/strong> : Having 2 distinct <em>setXXX()<\/em> and <em>setYYY()<\/em> functions implies that there exist 2 different properties. While you will know that both of the map to the same internally, this may NOT be obvious to someone new to your library\/API.<\/p>\n<p><strong>Logic<\/strong> : In addition to the set functions, you would be implementing the corresponding <code>getVisible()<\/code> and <code>getInvisible()<\/code> for good measure as well. With code snippets like the following sure to cause enough confusion.<\/p>\n<pre><code>setVisible()  \n...  \ngetInvisible()  \n\n(wait, what??)\n\nsetInVisible()  \n...  \ngetVisible()\n\n(whats the state now??)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I would say this is a BIG no-no due to the following reasons : Readability : There is only a very minor difference between the two keywords setVisible() and setInvisible() and its easy to mis-read while scrolling through 100s of lines of code. Semantics : Having 2 distinct setXXX() and setYYY() functions implies that there [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[],"class_list":["post-4394","post","type-post","status-publish","format-standard","hentry","category-semantic","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4394"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4394\/revisions"}],"predecessor-version":[{"id":8789,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4394\/revisions\/8789"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}