|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+Source code standards for libmaple.
|
|
|
2
|
+
|
|
|
3
|
+Do it like this unless there's a really good reason why not. You
|
|
|
4
|
+being a lazy bastard doesn't count as a good reason.
|
|
|
5
|
+
|
|
|
6
|
+The file .dir-locals.el in the libmaple root directory already ensures
|
|
|
7
|
+that many of these standards are followed by default, if you use emacs
|
|
|
8
|
+(and not Windows, where it would need to be named _dir_locals.el, and
|
|
|
9
|
+no way, man). There's also some elisp scattered about this file which
|
|
|
10
|
+will provide you additional help.
|
|
|
11
|
+
|
|
|
12
|
+Vim customizations to do the same thing would be nice!
|
|
|
13
|
+
|
|
|
14
|
+License
|
|
|
15
|
+-------
|
|
|
16
|
+
|
|
|
17
|
+- Put an MIT license at the beginning of the file (look at any of our
|
|
|
18
|
+ source files for an example). Copyright should go to either your or
|
|
|
19
|
+ LeafLabs LLC.
|
|
|
20
|
+
|
|
|
21
|
+ Emacs: if you don't like seeing the license, you should use
|
|
|
22
|
+ elide-head (which will hide it for you). Here is some elisp you can
|
|
|
23
|
+ modify to make this pleasant:
|
|
|
24
|
+
|
|
|
25
|
+ (require 'elide-head)
|
|
|
26
|
+ (setq programming-mode-hooks '(c-mode-hook c++-mode-hook))
|
|
|
27
|
+ (add-to-list 'elide-head-headers-to-hide
|
|
|
28
|
+ '("The MIT License" . "DEALINGS IN\n [*] THE SOFTWARE"))
|
|
|
29
|
+ (add-to-list 'elide-head-headers-to-hide
|
|
|
30
|
+ '("The MIT License" . "DEALINGS IN THE\n...SOFTWARE"))
|
|
|
31
|
+ (dolist (hook mbolivar-programming-mode-hooks)
|
|
|
32
|
+ (add-hook hook (lambda () (elide-head))))
|
|
|
33
|
+
|
|
|
34
|
+Whitespace
|
|
|
35
|
+----------
|
|
|
36
|
+
|
|
|
37
|
+- 4 space indents. [Set in .dir-locals.el]
|
|
|
38
|
+
|
|
|
39
|
+- Unix newlines.
|
|
|
40
|
+
|
|
|
41
|
+- No tab characters. [Set in .dir-locals.el]
|
|
|
42
|
+
|
|
|
43
|
+- No trailing whitespace. For help getting this (and no tab
|
|
|
44
|
+ characters) done automatically in Emacs, you can use this:
|
|
|
45
|
+
|
|
|
46
|
+ http://github.com/mbolivar/code-fascism
|
|
|
47
|
+
|
|
|
48
|
+ I hear tell you can get something similar in vim; ask Perry, I
|
|
|
49
|
+ guess.
|
|
|
50
|
+
|
|
|
51
|
+- Files end in exactly one newline. [The presence of a newline at EOF
|
|
|
52
|
+ is already done by `c-require-final-newline' in recent versions of
|
|
|
53
|
+ emacs.]
|
|
|
54
|
+
|
|
|
55
|
+- Exactly two newlines separate source paragraphs.
|
|
|
56
|
+
|
|
|
57
|
+- The first line in a function is non-blank.
|
|
|
58
|
+
|
|
|
59
|
+Comments
|
|
|
60
|
+--------
|
|
|
61
|
+
|
|
|
62
|
+- Multi-line comments look like this:
|
|
|
63
|
+
|
|
|
64
|
+ /* text starts here
|
|
|
65
|
+ * continued lines have a '*' before them
|
|
|
66
|
+ * the comment can end after the last line
|
|
|
67
|
+ */
|
|
|
68
|
+
|
|
|
69
|
+ or this:
|
|
|
70
|
+
|
|
|
71
|
+ /* comment starts here
|
|
|
72
|
+ * the comment can end on the same line */
|
|
|
73
|
+
|
|
|
74
|
+- Doxygen comments are newline comments that begin with /** instead.
|
|
|
75
|
+
|
|
|
76
|
+- Single-line comments on the same line are // in c or c++.
|
|
|
77
|
+
|
|
|
78
|
+- Single-line comments on their own source line are /* */ in c, but
|
|
|
79
|
+ can also be // in c++. If you think that typing out /* */ is too
|
|
|
80
|
+ slow in emacs, use M-; (comment-dwim) when you're on an empty line,
|
|
|
81
|
+ and it'll ... well...
|
|
|
82
|
+
|
|
|
83
|
+ You should be using the (super awesome) comment-dwim; it pretty
|
|
|
84
|
+ much does exactly what you want to the comment on the current
|
|
|
85
|
+ line, including "create one and put it in the right place".
|
|
|
86
|
+
|
|
|
87
|
+Braces
|
|
|
88
|
+------
|
|
|
89
|
+
|
|
|
90
|
+- 1TBS. Nothing more need be said.
|
|
|
91
|
+
|
|
|
92
|
+ http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS
|
|
|
93
|
+
|
|
|
94
|
+Naming conventions
|
|
|
95
|
+------------------
|
|
|
96
|
+
|
|
|
97
|
+So there's always a fight about upper and lower case vs. underscores.
|
|
|
98
|
+We'll handle this as follows. First, Dammit_Dont_Mix_Like_This,
|
|
|
99
|
+because It_Looks_Really_Ugly, ok?
|
|
|
100
|
+
|
|
|
101
|
+- Variables: Use underscores to separate words in C identifiers:
|
|
|
102
|
+
|
|
|
103
|
+ int some_example_name;
|
|
|
104
|
+
|
|
|
105
|
+ It is strongly advised to do it this way in C++ too, but it's not
|
|
|
106
|
+ [yet] mandatory.
|
|
|
107
|
+
|
|
|
108
|
+- Classes: Pascal case. So ThisIsAClassName, but thisIsNot,
|
|
|
109
|
+ this_is_not, and like I said, Dont_You_DareTryANYTHING_STUPID.
|
|
|
110
|
+
|
|
|
111
|
+- Functions: C functions are all lowercase, and words are separated by
|
|
|
112
|
+ underscores. C++ method names are camel cased.
|
|
|
113
|
+
|
|
|
114
|
+- Structs: pick a style from "Variables" or "Classes" depending on how
|
|
|
115
|
+ you mean it (since it might be either a simple record type, in which
|
|
|
116
|
+ case do like c variables, or you might be faking an object in c, in
|
|
|
117
|
+ which case do like classes). If it's in a typedef, should also
|
|
|
118
|
+ probably put _t at the end, but maybe you won't, and I don't really
|
|
|
119
|
+ feel too strongly about it.
|
|
|
120
|
+
|
|
|
121
|
+- Acronyms: The case of letters in an acronym is determined by the
|
|
|
122
|
+ case of the first letter in the acronym. Examples:
|
|
|
123
|
+
|
|
|
124
|
+ void usb_func() { ... }
|
|
|
125
|
+
|
|
|
126
|
+ class SomethingUSB {
|
|
|
127
|
+ void usbInit();
|
|
|
128
|
+ void initUSB();
|
|
|
129
|
+ };
|
|
|
130
|
+
|
|
|
131
|
+ NEVER DO THIS:
|
|
|
132
|
+
|
|
|
133
|
+ class BadUsb { ... }; // say "GoodUSB" instead
|
|
|
134
|
+
|
|
|
135
|
+- Macros and constants: all caps, separated by underscores.
|
|
|
136
|
+
|
|
|
137
|
+- foo.h gets ifdef'ed to _FOO_H_.
|
|
|
138
|
+
|
|
|
139
|
+Documentation
|
|
|
140
|
+-------------
|
|
|
141
|
+
|
|
|
142
|
+- Document your code, bitches!
|
|
|
143
|
+
|
|
|
144
|
+- At least put a doxygen comment with a nonempty @brief for every
|
|
|
145
|
+ source file you add. See the existing ones for examples.
|
|
|
146
|
+
|
|
|
147
|
+General Formatting
|
|
|
148
|
+------------------
|
|
|
149
|
+
|
|
|
150
|
+- Keep it 80-column clean. That means Emacs says the largest column
|
|
|
151
|
+ number=79. If you haven't already, you should turn on column
|
|
|
152
|
+ numbers to help you out:
|
|
|
153
|
+
|
|
|
154
|
+ (column-number-mode 1)
|
|
|
155
|
+
|
|
|
156
|
+ You can get more help from lineker-mode. Download it here:
|
|
|
157
|
+
|
|
|
158
|
+ http://www.helsinki.fi/~sjpaavol/programs/lineker.el
|
|
|
159
|
+
|
|
|
160
|
+ Then put the file somewhere in your load-path, and
|
|
|
161
|
+
|
|
|
162
|
+ (require 'lineker)
|
|
|
163
|
+ (dolist (hook programming-mode-hooks)
|
|
|
164
|
+ (add-hook hook (lambda () (lineker-mode 1))))
|