3 (This is not a most actively maintained file, but recommended
11 * Comments and Documentation
12 * Syntax-related Conventions
13 * Error and Warning Messages
20 Preferred patch format is output from "git format-patch", including
23 The commit message should explain the why and how of the change. See
24 existing commit messages for examples -- for a truly trivial changes
25 little is needed, but in most cases more is better.
27 Please include test-cases in your patch if at all possible: if you're
28 not sure which file in tests/ to put your test case in, just pick one
29 that seems vaguely appropriate. See the "Writing Tests" section for
32 Please format your submission for ease of reading: unless the change
33 is whitespace only, avoid re-indenting code you are not touching, etc.
35 Unless your change is large and best understood as a series of
36 sequential changes, please send it in as single patch.
38 If your patch includes algorithmic changes, explain them. If your
39 patch uses a published algorithm, please include a link to the paper.
40 We aren't always as well-educated as we'd like to be...
42 Ready-to-apply patches should be submitted via Launchpad: please add
43 the tag "review" to the associated bug (create new bug with name if
44 there isn't one about the issue yet.)
46 Patches requiring more widespread discussion and feedback should be
47 sent to the sbcl-devel mailing list.
49 If you have any questions, feel free to ask them on sbcl-devel,
50 or the IRC channel #sbcl@freenode.net.
55 See also PRINCIPLES and TLA files.
57 Most of the style hints in the Lisp FAQ apply.
59 When porting code we prefer code which factors dependencies into a set
60 of interface functions and constants and includes implementations of
61 the interface for the different systems.
63 Reader conditionals are frowed upon. Sometimes they're the least
64 of all evils, but think thrice.
66 grammatical fussiness:
67 Phrases are not capitalized.
68 Sentences are capitalized.
69 Periods terminate sentences.
70 Periods separate phrases from succeeding sentences, e.g.
71 ;;; the maximum number of transformations we'll make before
72 ;;; concluding we're in an infinite loop and bailing. This can
73 ;;; be changed, but it is an error to change it while we're
75 (defvar *max-n-transformations* 10)
76 Lisp in comments is capitalized.
77 Symbol names are capitalized.
80 Function documentation can be a description of what the function
82 ;;; Parse the arguments for a BDEFSTRUCT call, and return
83 ;;; (VALUES NAME DEFSTRUCT-ARGS MAKE-LOAD-FORM-FUN BDEFSTRUCT-STYPE),
84 ;;; where NAME is the name of the new type, DEFSTRUCT-ARGS is the
85 ;;; munged result suitable for passing on to DEFSTRUCT,
86 ;;; MAKE-LOAD-FORM-FUN is the make load form function, or NIL if
87 ;;; there's none, and BDEFSTRUCT-SUPERTYPE is the direct supertype
88 ;;; of the type if it is another BDEFSTRUCT-defined type, or NIL
90 (defun parse-bdefstruct-args (nameoid &rest rest)
92 or a remark about the function, e.g.
93 ;;; a helper function for BDEFSTRUCT in the #+XC-HOST case
94 (defun uncross-defstruct-args (defstruct-args)
96 If you're talking about what the function does, ordinarily you
97 should just say what the function does, e.g.
98 ;;; Return the first prime number greater than or equal to X.
99 (defun primify (x) ..)
100 instead of telling the reader that you're going to tell him what
101 the function does, e.g.
102 ;;; PRIMIFY returns the first prime number greater than or
104 (defun primify (x) ..)
106 ;;; When you call this function on X, you get back the first
107 ;;; prime number greater than or equal to X.
108 (defun primify (x) ..)
109 Documentation for public functions belongs in a docstring.
110 Documentation for internal functions belongs mostly in a comment.
112 In general, if you can express it in the code instead of the comments,
113 do so. E.g. the old CMUCL code has many comments above functions foo
116 If we were going to do something like that, we would prefer to do it by
119 (Instead, for various other reasons, we centralize all the exports
120 in package declarations.) The old "FOO -- interface" comments are bad
121 style because they duplicate information (and they illustrate one
122 of the evils of duplicating information by the way that they have
123 drifted out of sync with the code).
128 As mentioned in the "Patch Submissions" section, new features as well
129 as bug fixes should always be accompanied by smoke, unit or regression
130 tests as appropriate.
132 New tests should be added in the appropriate file in the "tests"
133 directory. Files named TOPIC.pure.lisp contain tests which do not have
134 side effects such as modifying the environment, defining functions or
135 variables or starting new threads while files named TOPIC.impure.lisp
136 contain test which do (impure test files are run each in a separate
139 All tests should use the WITH-TEST macro to associate a unique name
140 with each test (see below) and prevent a whole test file from going up
141 in smoke without an adequate description of the problem. The basic
144 (with-test (:name NAME)
147 where NAME is either a symbol or a list of symbols. All of these
148 symbols have to be in one of the packages KEYWORD, CL or SB-* to make
149 test names READable in SBCL images that did not read the test
150 files. For tests associated to Launchpad bugs (because a feature
151 requested in the LP bug has been implemented or a bug has been fixed),
152 the LP bug number should be a part of the test name:
154 (with-test (:name (coerce :invalid-target-type :bug-12345))
157 When a test can be associated to a name in the CL package or one of
158 the SB-* packages, that name should appear as a separate component in
159 the test name, like COERCE in the exaple above. This may be useful in
160 order to automatically associate functions and tests.
162 If possible, tests should not signal warnings during compilation or
163 runtime and should not produce output in order to not clutter the
164 output of the test runner and make real problems easier to identify.
169 There are a number of style practices on display in the code
170 which are not good examples to follow:
171 * using conditional compilation to support different architectures,
172 instead of factoring the dependencies into interfaces and providing
173 implementations of the interface for different architectures;
174 * in conditional compilation, using a common subexpression over and
175 over again, e.g. #+(OR X86 X86-64), when the important thing is
176 that the platform supports single-instruction CAS. If you have to
177 do something like that, define a new FOO feature, write #+FOO in
178 many places, and arrange for the FOO feature to be set once and
179 only once -- probably in make-config.sh. (That way future
180 maintainers won't curse you.)
181 * putting the defined symbol, and information about whether it's
182 exported or not, into the comments around the definition of the symbol;
183 * naming anything DO-FOO if it isn't an iteration macro
184 * not using a consistent abbreviation style in global names (e.g.
185 naming some things DEFINE-FOO and other things DEF-BAR, with
186 no rule to determine whether the abbreviation is used).
187 * using lots of single-colon package prefixes (distracting and hard
188 to read, and obstacles to reaching package nirvana where
189 package dependencies are a directed acyclic graph) or even
190 double-colon package prefixes (hard to understand and hard
191 to maintain). (One exception: I've sometimes been tempted to
192 add a CL: prefix to the definition of every CL symbol (e.g.
193 (DEFUN CL:CADDDR (..) ..) as reminders that they're required by
194 ANSI and can't be deleted no matter how obscure and useless some
195 of them might look.:-)
196 Many of these are common in the code inherited from CMUCL. We've
197 eliminated them in some places, but there's a *lot* of code inherited