Project

General

Profile

Coding Standards » History » Version 15

Tom Morris, 12/22/2016 07:05 PM

1 1 Tom Clegg
h1. Coding Standards
2
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
9 1 Tom Clegg
Make sure your name and email address are correct.
10
11
* Use @git config --global user.email foo@example.com@ et al.
12
* 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
14 9 Tom Clegg
Refer to a story number in each commit comment.
15
16
* @1234: Remove useless button.@
17
18
*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.
19
20
* @closes #1234@, or
21
* @refs #1234@
22
23 1 Tom Clegg
Use descriptive commit comments.
24
25
* Describe the delta between the old and new tree. If possible, describe the delta in *behavior* rather than the source code itself.
26 9 Tom Clegg
* Good: "1234: Support use of spaces in filenames."
27
* Good: "1234: Fix crash when user_id is nil."
28 1 Tom Clegg
* Less good: "Add some controller methods." (What do they do?)
29
* Less good: "More progress on UI branch." (What is different?)
30
* Less good: "Incorporate Tom's suggestions." (Who cares whose suggestions -- what changed?)
31
32
If further background or explanation is needed, separate it from the summary with a blank line.
33
34
* Example: "Users found it confusing that the boxes had different colors even though they represented the same kinds of things."
35
36 13 Tom Clegg
h2. Source code formatting
37 1 Tom Clegg
38 13 Tom Clegg
(Unless otherwise specified by style guide...)
39
40 10 Tom Clegg
No TAB characters in source files. "Except go programs.":https://golang.org/cmd/gofmt/
41 1 Tom Clegg
42 6 Tom Clegg
* Emacs: add to @~/.emacs@ → @(setq-default indent-tabs-mode nil)@
43
* Vim: add to @~/.vimrc@ → @:set expandtab@
44 8 Tom Clegg
* See [[Coding Standards#Git setup|Git setup]] below
45 4 Ward Vandewege
46 6 Tom Clegg
No inline comments: @this = !desired; # we don't want to do it.@
47 4 Ward Vandewege
48 6 Tom Clegg
No long (>80 column) lines, except in rare cases when the alternative is really clunky.
49
50 4 Ward Vandewege
No whitespace at the end of lines. Make git-diff show you:
51 5 Ward Vandewege
52
  git config color.diff.whitespace "red reverse"
53 6 Tom Clegg
git diff --check
54 1 Tom Clegg
55 13 Tom Clegg
h2. What to include
56
57 1 Tom Clegg
No commented-out blocks of code that have been replaced or obsoleted.
58
59
* It is in the git history if we want it back.
60
* 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.
61
62
No commented-out debug statements.
63
64
* 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"@
65
66 13 Tom Clegg
h2. Style mismatch
67
68 1 Tom Clegg
Adopt indentation style of surrounding lines or (when starting a new file) the nearest existing source code in this tree/language.
69
70
If you fix up existing indentation/formatting, do that in a separate commit.
71
* If you bundle formatting changes with functional changes, it makes functional changes hard to find in the diff.
72
73 13 Tom Clegg
h2. Go
74
75
gofmt, golint, etc., and https://github.com/golang/go/wiki/CodeReviewComments
76
77
h2. Ruby
78
79
https://github.com/bbatsov/ruby-style-guide
80
81 1 Tom Clegg
h2. Python
82 13 Tom Clegg
83
PEP-8.
84 12 Tom Clegg
85
Tell Emacs you don't want a blank line at the end of a multiline docstring.
86
87
    (setq python-fill-docstring-style 'pep-257-nn)
88
89 11 Brett Smith
h2. JavaScript
90
91 15 Tom Morris
"Always use 3 equals unless you have a good reason to use 2.":https://github.com/airbnb/javascript#comparison--eqeqeq
92 14 Tom Morris
"Use 2 spaces for indents":https://github.com/airbnb/javascript#whitespace--spaces
93
94
Follow the Airbnb Javascript coding style guide unless otherwise stated (the rules above are for emphasis, not exceptions)
95
https://github.com/airbnb/javascript
96
97 11 Brett Smith
98 7 Tom Clegg
h2. Git setup
99 6 Tom Clegg
100 7 Tom Clegg
Configure git to prevent you from committing whitespace errors.
101 1 Tom Clegg
102 6 Tom Clegg
<pre>
103 7 Tom Clegg
git config --global core.whitespace tab-in-indent,trailing-space
104
git config --global apply.whitespace error
105 6 Tom Clegg
</pre>