Project

General

Profile

Coding Standards » History » Revision 11

Revision 10 (Tom Clegg, 08/28/2014 09:48 AM) → Revision 11/30 (Brett Smith, 01/05/2015 03:42 PM)

h1. Coding Standards 

 The rules are always up for debate. However, when debate is needed, it should happen outside the source tree. In other words, if the rules are wrong, first debate the rules in IRC etc., then fix the rules, then follow the new rules. 

 {{toc}} 

 

 h2. Git commits 

 Make sure your name and email address are correct. 

 * Use @git config --global user.email foo@example.com@ et al. 
 * It's a little unfortunate to have commits with author @foo@myworkstation.local@ but not bad enough to rewrite history, so fix this before you push! 

 Refer to a story number in each commit comment. 

 * @1234: Remove useless button.@ 

 *When merging/committing to master,* refer to the story number in a way Redmine will notice. Redmine will list these commits/merges on the story page itself. 

 * @closes #1234@, or 
 * @refs #1234@ 

 Use descriptive commit comments. 

 * Describe the delta between the old and new tree. If possible, describe the delta in *behavior* rather than the source code itself. 
 * Good: "1234: Support use of spaces in filenames." 
 * Good: "1234: Fix crash when user_id is nil." 
 * Less good: "Add some controller methods." (What do they do?) 
 * Less good: "More progress on UI branch." (What is different?) 
 * Less good: "Incorporate Tom's suggestions." (Who cares whose suggestions -- what changed?) 

 If further background or explanation is needed, separate it from the summary with a blank line. 

 * Example: "Users found it confusing that the boxes had different colors even though they represented the same kinds of things." 

 

 h2. Source files 

 No TAB characters in source files. "Except go programs.":https://golang.org/cmd/gofmt/ 

 * Emacs: add to @~/.emacs@ → @(setq-default indent-tabs-mode nil)@ 
 * Vim: add to @~/.vimrc@ → @:set expandtab@ 
 * See [[Coding Standards#Git setup|Git setup]] below 

 No inline comments: @this = !desired; # we don't want to do it.@ 

 No long (>80 column) lines, except in rare cases when the alternative is really clunky. 

 No whitespace at the end of lines. Make git-diff show you: 

   git config color.diff.whitespace "red reverse" 
 git diff --check 

 No commented-out blocks of code that have been replaced or obsoleted. 

 * It is in the git history if we want it back. 
 * If its absence would confuse someone reading the new code (despite never having read the old code), explain its absence in an English comment. If the old code is really still needed to support the English explanation, then go ahead -- now we know why it's there. 

 No commented-out debug statements. 

 * If the debug statements are likely to be needed in the future, use a logging facility that can be enabled at run time. @logger.debug "foo"@ 

 Adopt indentation style of surrounding lines or (when starting a new file) the nearest existing source code in this tree/language. 

 If you fix up existing indentation/formatting, do that in a separate commit. 

 * If you bundle formatting changes with functional changes, it makes functional changes hard to find in the diff. 

 h2. JavaScript 

 "Always use 3 equals unless you have a good reason to use 2.":http://dorey.github.io/JavaScript-Equality-Table/ 

 

 h2. Git setup 

 Configure git to prevent you from committing whitespace errors. 

 <pre> 
 git config --global core.whitespace tab-in-indent,trailing-space 
 git config --global apply.whitespace error 
 </pre>