{"id":209,"date":"2009-03-04T00:00:13","date_gmt":"2009-03-04T07:00:13","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=882"},"modified":"2009-03-04T00:00:13","modified_gmt":"2009-03-04T07:00:13","slug":"readable-conditionals","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=209","title":{"rendered":"Readable Conditionals"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/ NOTE: this code won&#039;t do anything in you&#039;re timline....\r\n\r\n\/\/ do you do this?\r\n\r\nif (ball.x &lt; 0 || ball.y &lt; 0 || ball.x &gt; stage.stageWidth || ball.y &gt; stage.stageHeight){\r\n       \/\/ cause ball to explode\r\n}\r\n\r\n\/\/ or this?\r\n\r\nif (isAtStageEdge(ball)){\r\n       \/\/ cause ball to explode\r\n}\r\n\r\nfunction isAtStageEdge(mc:MovieClip):Boolean{\r\n   return (mc.x &lt; 0 || mc.y &lt; 0 || mc.x &gt; stage.stageWidth || mc.y &gt; stage.stageHeight);\r\n}\r\n<\/pre>\n<p>This is pretty standard stuff, but it can increase code readability especially for complex conditionals.<\/p>\n<p>I also do this if I find myself repeating an a semi-complex if statement in two or more places.<\/p>\n<p>If I&#8217;m just brainstorming I probably won&#8217;t bother, but on real projects it helps keep code readable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ NOTE: this code won&#039;t do anything in you&#039;re timline&#8230;. \/\/ do you do this? if (ball.x &lt; 0 || ball.y &lt; 0 || ball.x &gt; stage.stageWidth || ball.y &gt; stage.stageHeight){ \/\/ cause ball to explode } \/\/ or this? if (isAtStageEdge(ball)){ \/\/ cause ball to explode } function isAtStageEdge(mc:MovieClip):Boolean{ return (mc.x &lt; 0 || [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[3,4],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-functions","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=209"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/209\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}