Coding Standards » History » Version 5

Ward Vandewege, 03/19/2014 04:30 PM

1 1 Tom Clegg
h1. Coding Standards
2 1 Tom Clegg
3 3 Tom Clegg
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.
4 1 Tom Clegg
5 2 Tom Clegg
{{toc}}
6 1 Tom Clegg
7 2 Tom Clegg
h2. Git commits
8 2 Tom Clegg
9 1 Tom Clegg
Make sure your name and email address are correct.
10 1 Tom Clegg
11 1 Tom Clegg
* Use @git config --global user.email foo@example.com@ et al.
12 1 Tom Clegg
* 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!
13 1 Tom Clegg
14 1 Tom Clegg
Use descriptive commit comments.
15 1 Tom Clegg
16 1 Tom Clegg
* Describe the delta between the old and new tree. If possible, describe the delta in *behavior* rather than the source code itself.
17 1 Tom Clegg
* Good: "Support use of spaces in filenames."
18 1 Tom Clegg
* Good: "Fix crash when user_id is nil."
19 1 Tom Clegg
* Less good: "Add some controller methods." (What do they do?)
20 1 Tom Clegg
* Less good: "More progress on UI branch." (What is different?)
21 1 Tom Clegg
* Less good: "Incorporate Tom's suggestions." (Who cares whose suggestions -- what changed?)
22 1 Tom Clegg
23 1 Tom Clegg
If further background or explanation is needed, separate it from the summary with a blank line.
24 1 Tom Clegg
25 1 Tom Clegg
* Example: "Users found it confusing that the boxes had different colors even though they represented the same kinds of things."
26 1 Tom Clegg
27 1 Tom Clegg
Refer to issues in git commits.
28 1 Tom Clegg
29 1 Tom Clegg
* Redmine notices "refs #12345" and "closes #12345" and "fixes #12345" in commit messages, and links to the commits from the issue page.
30 2 Tom Clegg
31 2 Tom Clegg
h2. Source files
32 1 Tom Clegg
33 1 Tom Clegg
No TAB characters in source files.
34 1 Tom Clegg
35 4 Ward Vandewege
* Emacs: use @(setq-default indent-tabs-mode nil)@ or equivalent.
36 4 Ward Vandewege
* Vim: add to your .vimrc:
37 4 Ward Vandewege
38 4 Ward Vandewege
<pre>
39 4 Ward Vandewege
  :set expandtab
40 4 Ward Vandewege
</pre>
41 4 Ward Vandewege
42 5 Ward Vandewege
No whitespace at the end of lines. Make git-diff show you:
43 5 Ward Vandewege
44 5 Ward Vandewege
  git config color.diff.whitespace "red reverse"
45 1 Tom Clegg
46 1 Tom Clegg
No commented-out blocks of code that have been replaced or obsoleted.
47 1 Tom Clegg
48 1 Tom Clegg
* It is in the git history if we want it back.
49 1 Tom Clegg
* 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.
50 1 Tom Clegg
51 1 Tom Clegg
No commented-out debug statements.
52 1 Tom Clegg
53 1 Tom Clegg
* 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"@
54 1 Tom Clegg
55 1 Tom Clegg
Adopt indentation style of surrounding lines or (when starting a new file) the nearest existing source code in this tree/language.
56 1 Tom Clegg
57 1 Tom Clegg
If you fix up existing indentation/formatting, do that in a separate commit.
58 1 Tom Clegg
59 1 Tom Clegg
* If you bundle formatting changes with functional changes, it makes functional changes hard to find in the diff.