Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You know that there <em>are</em> conventions for naming artifacts in a program?</p> <p>For example, Java has come up with a pretty strong and reliable way of naming classes, methods and attributes.</p> <p>Wikipedia has this to say about naming convention (not too helpful, but still interesting) <a href="http://en.wikipedia.org/wiki/Naming_convention_(programming)" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Naming_convention_(programming)</a></p> <p>Here is a page from Central Washington University (with Java, but still helpful for other programming languages) : <a href="http://www.cwu.edu/~gellenbe/javastyle/naming.html" rel="nofollow noreferrer">http://www.cwu.edu/~gellenbe/javastyle/naming.html</a></p> <p>Other article here : <a href="http://drupal.star.bnl.gov/STAR/comp/sofi/soft-n-libs/standards/NamingAdvice" rel="nofollow noreferrer">http://drupal.star.bnl.gov/STAR/comp/sofi/soft-n-libs/standards/NamingAdvice</a></p> <p>But basically, naming a method usually start with a action, then a noun, etc.</p> <p>For example:</p> <pre><code>$obj.addObservers(...); // action, noun $obj.setPrice(); // action, noun $obj.getModelFromDb(); // action, noun, preposition, noun $obj.setActive(...); // action, noun $obj.isActive(); // yes (true) or no (false) statement $obj.canEdit(); // yes (true) or no (false) statement $obj.setCanEdit(); // action, attribute // etc. </code></pre> <p>Avoid using negative method naming, ex: <code>$obj.cannotConnect();</code> which will simply confuse everyone. (This is also true when prompting, ex: "You are about to delete this file, do you want to abort?" ... choosing 'no' thinking you are going to delete a file and it was a mistake will do the opposite...)</p> <p>Back to method naming; </p> <ul> <li>your method names should be as short as possible, but avoid using acronyms, unless the method name is too long (this is a judgement call here); </li> <li>methods should be self explanatory and self documented;</li> <li>avoid using prefixes, unless you are working with non-OOP languages (pretty rare these days). Your prefix should be your class, or namespace, etc.</li> <li>each method should have only one function (one purpose) if you method does more than one thing, consider splitting that method into many, and call each of them inside a method (like <code>doActionBatch()</code>, where 'ActionBatch' is the name of the actual action to perform; Ex: <code>doHttpConnect()</code></li> <li>etc.</li> </ul> <p>A tip I may suggest is to read programs written by the community; they usual adopt best practices in naming conventions and you will get more familiar with "how methods are named"</p>
    singulars
    1. This table or related slice is empty.
    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.
    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