Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Many of these coding standards are very subjective, but some important things to consider are:</p> <ol> <li><p>Get a single set of code naming and style rules, and follow them. If you don't have already defined rules, make sure to get rules figured out. Then work at refactoring the code to follow them. This is an important step in order to make it easier for new developers to jump on board, and keep the coding consistent among developers.</p></li> <li><p>It takes time and effort to change the coding standards your company puts in place. Any change to the rules means that the code really has to be gone through again to update everything to be consistent with the new standards.</p></li> </ol> <p>Keeping the above in mind, and looking more along the lines of specific PHP coding standards. The first thing to look at is if your company uses any sort of framework, look at the coding standards for that framework as you may want to stick with those in order to stay consistent across all the code. I have listed links to a couple of the popular PHP frameworks below:</p> <ol> <li><a href="http://framework.zend.com/manual/en/coding-standard.naming-conventions.html" rel="nofollow noreferrer">Zend Framework Naming Conventions</a> and <a href="http://framework.zend.com/manual/en/coding-standard.coding-style.html" rel="nofollow noreferrer">Zend Framework Code Style</a></li> <li><a href="http://pear.php.net/manual/en/standards.php" rel="nofollow noreferrer">Pear Code Standards</a></li> </ol> <p>My personal preference in regards to your specific coding styles:</p> <p><strong>1. camelCase: Functions, class names, methods, and variables must be camelCase</strong></p> <p><em>Class names</em> should be Pascal Case (Upper Camel Case).</p> <p>So in your example:</p> <pre><code>class CustomerServiceBillingInstance { // Your class code here } </code></pre> <p><em>Variables</em> and <em>functions</em> I generally feel should be camel case.</p> <p>So either one of these, depending on your preference in terms of underscores:</p> <pre><code>$customerServiceBillingInstance = whatever; $customer_service_billing_instance = whatever; </code></pre> <p><strong>2. Functions/methods must always return a value (and returned values must always be stored).</strong></p> <p>This one seems like extra code and like you could end up using extra resources. If a function doesn't need to return anything, don't return anything. Likewise, if you do not care about what a function returns, don't store it. There is no point in using the extra memory to store something you are never going to look at.</p> <p>An interesting thing you may want to try on this one, is running some benchmarks. See if it takes extra time to return something and store it even though you are not looking at it.</p> <p><strong>3. Your code is not OOP unless everything returns an object</strong></p> <p>In this instance, I feel you have to draw the line somewhere. Performance wise, it is faster for you to do:</p> <pre><code>return false; </code></pre> <p>Than to do:</p> <pre><code>return new Boolean(false); // This would use up unnecessary resources but not add very much to readability or maintainability in my opinion. </code></pre> <hr> <p><strong>Defending a coding standard</strong></p> <p>To defend a coding standard that you feel is right (or showing why another is not as good), you really are going to have to bring up one of two points.</p> <ol> <li><p><strong>Performance</strong>. If you can show that a particular coding standard is adversely affecting performance, you may want to consider switching.</p></li> <li><p><strong>Maintainability/Readability</strong>. Your code should be easy to read/understand.</p></li> </ol> <p>The goal is to find the happy median between performance and the maintainability/readability. Sometimes it is an easy decision because the most maintainable option is also the best performing, other times there is a harder choice to be made.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload