1.0.41.49: comment on patch submission formats in STYLE
[sbcl.git] / STYLE
1 SBCL Style Guide
2
3   (This is not a most actively maintained file, but recommended
4   reading anyways.)
5
6 Patch Submissions
7 =================
8
9 Preferred patch format is output from "git format-patch", but unified
10 diffs and links to public git repos are acceptable as well.
11
12 Please include test-cases in your patch if possible.
13
14 Please format your submission for ease of reading: unless the change
15 is whitespace only, avoid re-indenting code you are not touching, etc.
16 Unless your patch is large and best understood as a series of
17 sequential changes, please send it in as single patch file.
18
19 If your patch includes algorithmic changes, explain them. If your
20 patch uses a published algorithm, please include a link to the paper.
21 We aren't always as well-educated as we'd like to...
22
23 Patches can be either mailed to sbcl-devel, or submitted via
24 Launchpad. If you submit a patch on Launchpad, please add the tag
25 "review" to the associated bug.
26
27 If you have any questions, feel free to ask them on sbcl-devel.
28
29 Coding Style
30 ============
31
32 See also PRINCIPLES and TLA files.
33
34 Most of the style hints in the Lisp FAQ apply.
35
36 When porting code we prefer code which factors dependencies into a set
37 of interface functions and constants and includes implementations of
38 the interface for the different systems. Patches which require
39 conditional compilation (like all the old
40 #T+HPUX or #T-X86 tests in the sources inherited from CMUCL) might be
41 accepted if they're simple, in hopes of factoring out the differences
42 more cleanly later, but even if accepted, such code may not be
43 maintained for very long.
44
45 grammatical fussiness:
46   Phrases are not capitalized.
47   Sentences are capitalized.
48   Periods terminate sentences.
49   Periods separate phrases from succeeding sentences, e.g.
50     ;;; the maximum number of transformations we'll make before
51     ;;; concluding we're in an infinite loop and bailing. This can
52     ;;; be changed, but it is an error to change it while we're
53     ;;; solving a system.
54     (defvar *max-n-transformations* 10)
55   Lisp in comments is capitalized.
56
57 usage fussiness:
58   Function documentation can be a description of what the function
59     does, e.g.
60         ;;; Parse the arguments for a BDEFSTRUCT call, and return
61         ;;;   (VALUES NAME DEFSTRUCT-ARGS MAKE-LOAD-FORM-FUN BDEFSTRUCT-STYPE),
62         ;;; where NAME is the name of the new type, DEFSTRUCT-ARGS is the
63         ;;; munged result suitable for passing on to DEFSTRUCT,
64         ;;; MAKE-LOAD-FORM-FUN is the make load form function, or NIL if
65         ;;; there's none, and BDEFSTRUCT-SUPERTYPE is the direct supertype
66         ;;; of the type if it is another BDEFSTRUCT-defined type, or NIL
67         ;;; otherwise.
68         (defun parse-bdefstruct-args (nameoid &rest rest)
69           ..)
70     or a remark about the function, e.g.
71         ;;; a helper function for BDEFSTRUCT in the #+XC-HOST case
72         (defun uncross-defstruct-args (defstruct-args)
73           ..)
74     If you're talking about what the function does, ordinarily you
75     should just say what the function does, e.g.
76         ;;; Return the first prime number greater than or equal to X.
77         (defun primify (x) ..)
78     instead of telling the reader that you're going to tell him what
79     the function does, e.g.
80         ;;; PRIMIFY returns the first prime number greater than or 
81         ;;; equal to X.
82         (defun primify (x) ..)
83     or 
84         ;;; When you call this function on X, you get back the first
85         ;;; prime number greater than or equal to X.
86         (defun primify (x) ..)
87
88 In general, if you can express it in the code instead of the comments,
89 do so. E.g. the old CMUCL code has many comments above functions foo
90 that say things like
91         ;;; FOO -- interface
92 If we were going to do something like that, we would prefer to do it by
93 writing
94         (EXPORT 'FOO)
95 (Instead, for various other reasons, we centralize all the exports
96 in package declarations.) The old "FOO -- interface" comments are bad
97 style because they duplicate information (and they illustrate one
98 of the evils of duplicating information by the way that they have
99 drifted out of sync with the code).
100
101 There are a number of style practices on display in the code
102 which are not good examples to follow:
103   * using conditional compilation to support different architectures,
104     instead of factoring the dependencies into interfaces and providing
105     implementations of the interface for different architectures;
106   * in conditional compilation, using a common subexpression over and
107     over again, e.g. #+(OR GENGC GENCGC), when the important thing is
108     that GENGC and GENCGC are (currently) the GCs which support scavenger
109     hooks. If you have to do that, define a SCAVHOOK feature,
110     write #+SCAVHOOK in many places, and arrange for the SCAVHOOK feature
111     to be set once and only once in terms of GENGC and GENCGC. (That way
112     future maintainers won't curse you.)
113   * putting the defined symbol, and information about whether it's 
114     exported or not, into the comments around the definition of the symbol;
115   * naming anything DO-FOO if it isn't an iteration macro
116   * exposing a lot of high-level functionality not in the ANSI standard
117     to the user (as discussed above)
118   * not using a consistent abbreviation style in global names (e.g. 
119     naming some things DEFINE-FOO and other things DEF-BAR, with 
120     no rule to determine whether the abbreviation is used)
121   * using lots of single-colon package prefixes (distracting and hard
122     to read, and obstacles to reaching package nirvana where 
123     package dependencies are a directed acyclic graph) or even
124     double-colon package prefixes (hard to understand and hard
125     to maintain). (One exception: I've sometimes been tempted to
126     add a CL: prefix to the definition of every CL symbol (e.g.
127     (DEFUN CL:CADDDR (..) ..) as reminders that they're required by
128     ANSI and can't be deleted no matter how obscure and useless some
129     of them might look.:-)
130 Most of these are common in the code inherited from CMUCL. We've
131 eliminated them in some places, but there's a *lot* of code inherited
132 from CMUCL..