Code cleanup & factoring of commands module.
[rpn.git] / STYLE
blob6850cbe7b617bcfc002df74b0de5975135e74682
1 Style Guide for RPN
2 by Samuel Fredrickson <kinghajj@gmail.com>
3 2008-11-27
5 0. About this Document
6 ----------------------
8     This is a simple style guideline for the RPN project. All code in the
9     project must follow these rules, which are subject to change at any time.
11 1. Tabs, Spaces and Alignment
12 -----------------------------
14     No tabs. Uses spaces to indent and align. I formally advocated tabs to
15     indent and spaces to align, but I've come to find that that makes me waste
16     too much time making sure that there wasn't some tab where it shouldn't be.
17     Using spaces is easier.
19     Indent blocks with 4 spaces. No exceptions.
21     Here's some examples of how you should align.
23 int RPN_hereIsALongFunctionWithSomeSmallParameters(int firstParam,
24                                                    int secondParam);
25 int RPN_andHereIsALongFunctionWithManyLongParameters(int a, double b,
26                                                      RPN_Calculator *calc);
27 int RPN_thisNameIsWayTooLongButIsIncludedJustInCaseItsEverNeeded(
28     RPNCalculator *calc, RPNValue v);
30     And here's an example definition of a function.
32 int RPN_hereIsALongFunctionWithManyLongParameters(int firstParam,
33                                                   int secondParam)
35     if(firstParam == secondParam)
36         RPN_printf("firstParam == secondParam\n");
37     return firstParam + secondParam;
40     You may also choose to align assignments if it's logical to do so. But
41     again, use spaces to align to keep the alignment portable.
43 2. Curly Bracket Placement
44 --------------------------
46     I prefer the BSD/Allman style, which puts curly brackets on their own line
47     with the same indentation as the control structure or function, but I'm
48     tolerant of the K&R style. The GNU and Pico styles are just ugly.
50 3. Variable Declaration
51 -----------------------
53     Although C++ compilers let you declare a variable anywhere within a
54     function, for this project, declare most variables at the beginning. Writing
55     the variables you think you'll need can help you plan a function, and having
56     all declarations together can make it easier to remove unneeded ones.
57     However, if there is a variable used in only one block, it's fine to just
58     put it there.
60 4. 80-Column Limit
61 ------------------
63     Always stay within the 80-column limit. No exceptions.