{"id":245,"date":"2018-02-06T07:00:00","date_gmt":"2018-02-06T14:00:00","guid":{"rendered":"https:\/\/coreassistance.com\/tips\/?p=245"},"modified":"2018-02-01T13:51:13","modified_gmt":"2018-02-01T20:51:13","slug":"naming-functions-and-keeping-them-simple","status":"publish","type":"post","link":"https:\/\/coreassistance.com\/tips\/2018\/02\/06\/naming-functions-and-keeping-them-simple\/","title":{"rendered":"Naming Functions &#038; Keeping Them Simple"},"content":{"rendered":"<p>Every time I write a function or method, I take a moment to describe it to myself in plain English.  Doing so serves two purposes: It helps me determine if the function is too complex, and it helps me come up with a good name for the function.<\/p>\n<p><strong>If the description I come up with for a function is more than a single sentence, or if that single sentence contains the word &#8220;and&#8221;, that indicates the function is too complex.<\/strong>  In order to keep code understandable and maintainable, each function should serve a single purpose.  There are, of course, exceptions to this rule, but they&#8217;re few and far between.<\/p>\n<p>If a function does more than one thing it&#8217;s likely I&#8217;ll end up needing to do those individual things separately at some point in the future, so it&#8217;s a good idea to stop and break the function up into individual pieces now before things get too out of hand.  It&#8217;s also much easier to understand and maintain code that&#8217;s broken up into small, easy-to-digest chunks with few (if any) dependencies on each other.<\/p>\n<p>Once I have a function that produces a proper single-sentence, single-purpose description it&#8217;s usually easy to turn that sentence into a good, descriptive name for the function.  Reduced code complexity and great function and method names with one simple technique!<\/p>\n<p>So, how would you describe your functions?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A simple method to both name functions well and keep your code manageable.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":10,"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/posts\/245\/revisions\/366"}],"wp:attachment":[{"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coreassistance.com\/tips\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}