{"id":2821,"date":"2025-07-30T14:51:35","date_gmt":"2025-07-30T13:51:35","guid":{"rendered":"https:\/\/home.andperry.com\/andperry.com\/?page_id=2821"},"modified":"2026-08-02T13:34:32","modified_gmt":"2026-08-02T12:34:32","slug":"coding-standards","status":"publish","type":"page","link":"https:\/\/home.andperry.com\/andperry.com\/itservices\/coding-standards\/","title":{"rendered":"Coding Standards"},"content":{"rendered":"<p>This page defines the coding standards that I use for software development.<\/p>\n<h2>General Standards<\/h2>\n<h3>Indentation<\/h3>\n<p>Spaces shall be used as opposed to tabs, and an indentation level of 4 shall be maintained.<\/p>\n<h2>PHP Standards<\/h2>\n<h3>Naming<\/h3>\n<ul>\n<li>Variables, functions and classes shall normally be named using snake case (lowercase, underscores and numerals).<\/li>\n<li>Constants shall normally be named using uppercase, underscores and numerals.<\/li>\n<li>Exceptions may be applied where there is reason to do so.<\/li>\n<\/ul>\n<h3>Use of Braces<\/h3>\n<ul>\n<li>For class and function declarations, the opening brace (curly bracket) shall be placed on a new line.<\/li>\n<li>Code within conditions and loops shall always be enclosed in braces, even when there is only a single line of code involved.<\/li>\n<li>For logic control (conditional statements, loops etc.), the opening brace shall be placed at the end of the control statement (<em>if<\/em>, <em>for<\/em>, <em>while<\/em> etc.) on the same line, with a single preceding space.<\/li>\n<li>The closing brace for a statement or block shall always be placed on a new line.<\/li>\n<li><em>else<\/em> and <em>elseif<\/em> directives shall start on a new line, rather than follow a closing brace on the same line. For consistency with this standard, the <em>while<\/em> directive at the end of a <em>do<\/em> loop should also be placed on a new line.<\/li>\n<\/ul>\n<h3>Arrays<\/h3>\n<ul>\n<li>The short syntax (with square brackets) shall be used at all times.<\/li>\n<li>An array declaration may be placed on a single line where space allows.<\/li>\n<li>Where more than one line is required, the first line shall end with the opening square bracket, with the array elements on the following lines at the next level of indentation, and the closing square bracket on a line of its own at the indentation level of the opening line.<\/li>\n<\/ul>\n<h3>Ternary and Null Coalesce Operators<\/h3>\n<ul>\n<li>The use of the ternary and null coalesce operators shall be encouraged wherever possible, but by way of discretion rather than as a mandatory requirement.\n<li>An assignment with the ternary operator <em>[var = (cond) ? val1 : val2]<\/em> shall be placed on a single line where space permits. If more lines are required, the second line shall start with the '?' at the next level of indentation, and the ':' shall appear on a new line directly below the '?'.<\/li>\n<li>An assignment with the null coalesce operator <em>[var = val1 ?? val2]<\/em>  shall be placed on a single line where space permits. If more lines are required, the second line shall start with the '??' at the next level of indentation.<\/li>\n<\/ul>\n<h3>Constant Definitions<\/h3>\n<p>The <em>define<\/em> construct (as opposed to <em>const<\/em>) shall be used at all times. This provides a consistent standard whilst allowing for the use of conditional definitions.<\/p>\n<h3>Use of <em>exit<\/em> and <em>die<\/em><\/h3>\n<p>The <em>exit<\/em> directive shall be used in production for controlled exit points, whilst <em>die<\/em> shall be reserved for debug test points.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page defines the coding standards that I use for software development. General Standards Indentation Spaces shall be used as opposed to tabs, and an indentation level of 4 shall be maintained. PHP Standards Naming Variables, functions and classes shall normally be named using snake case (lowercase, underscores and numerals). Constants shall normally be named [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":367,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-2821","page","type-page","status-publish","hentry"],"acf":[],"distributor_meta":false,"distributor_terms":false,"distributor_media":false,"distributor_original_site_name":"Andrew Perry","distributor_original_site_url":"https:\/\/home.andperry.com\/andperry.com","push-errors":false,"_links":{"self":[{"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/pages\/2821","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/comments?post=2821"}],"version-history":[{"count":0,"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/pages\/2821\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/pages\/367"}],"wp:attachment":[{"href":"https:\/\/home.andperry.com\/andperry.com\/wp-json\/wp\/v2\/media?parent=2821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}