Coding standards

Parting Words

Be consistent.

If you’re editing code, take a few minutes to look at the code around you and determine its style. If they use spaces around all their arithmetic operators, you should too. If their comments have little boxes of hash marks around them, make your comments have little boxes of hash marks around them too.

The point of having style guidelines is to have a common vocabulary of coding so people can concentrate on what you’re saying rather than on how you’re saying it. We present global style rules here so people know the vocabulary, but local style is also important. If code you add to a file looks drastically different from the existing code around it, it throws readers out of their rhythm when they go to read it. Avoid this.

PHP

See CakePHP Coding Standards.

References

  1. CakePHP Coding Standards
  2. CakePHP Code Sniffer

JavaScript

See Principles of Writing Consistent, Idiomatic JavaScript.

Clarifications (or exceptions to the rules)

  1. Use real tabs (\t)

  2. "inner whitespace" must be avoided. See D. Consistency Always Wins., 2.D.1.1

     // Bad
     if ( condition ) {
       // statements
     }
    
     // Good
     if (condition) {
       // statements
     }
  3. Use single quotes

     var dev = 'monkey';

Further reading

  1. Google JavaScript Style Guide

Git

Commit messages

Capitalized, short (50 chars or less) summary

More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.

Write your commit message in the present tense: "Fix bug" and not "Fixed bug." This convention matches up with commit messages generated by commands like git merge and git revert.

Further paragraphs come after blank lines.

References

  1. A note about Git commit messages