diff --git a/lispguide.xml b/lispguide.xml index 8ef1dc9..2933ebb 100644 --- a/lispguide.xml +++ b/lispguide.xml @@ -5,7 +5,7 @@

-Revision 1.12 +Revision 1.13

@@ -46,8 +46,27 @@ Robert Brown

Common Lisp is a powerful multiparadigm programming language. With great power comes great responsibility. +

+

This guide recommends formatting and stylistic choices designed to make your code easier for other people to understand. + Its guidelines apply to all the Common Lisp code we write at Google, + including our internal applications as well as + free software libraries we maintain and publish. + If you contribute to this code base, + you must follow these guidelines before you submit your patch, + or your code will be fixed to follow the guidelines after you do. +

+

+ If you're writing Common Lisp code outside Google, + we invite you to consider the guidelines we expound in this guide. + You may apply some or all of them to your own projects, at your leisure. + If you do, we hope that you will find some of them useful. + Even if you don't, we also welcome any remarks or constructive feedback + you may have on how to improve our guide, and + about what alternate styles are available. + Finally, we hope that our discussions will be thought-inspiring + to hackers who read them, especially so to newcomers to Common Lisp.

@@ -141,8 +160,9 @@ Robert Brown

- Permission comes from the OWNERS of your project. + Permission comes from the owners of your project.

+

Forgiveness is requested in a comment near the point of guideline violation, @@ -168,7 +188,16 @@ Robert Brown Whatever the case may be, you must still follow these guidelines, as well as other conventional guidelines that have not been formalized in this document. - You MUST follow conventions, because they are important for readability. +

+

+ You MUST follow conventions. + They are important for readability. + When conventions are followed by default, + violations of the convention are a signal + that something notable is happening and deserves attention. + When conventions are systematically violated, + violations of the convention are a distracting noise + that needs to be ignored.

Conventional guidelines are indoctrination. @@ -451,7 +480,7 @@ Robert Brown

- Use your judgement to distinguish + Use your judgment to distinguish general-purpose versus business-specific code, and open-source the general-purpose parts, while keeping the business-specific parts a trade secret. @@ -630,8 +659,10 @@ Robert Brown

Some line length restriction is better than none at all. - Allowing 100 columns seems better, since good style encourages - the use of descriptive variables and function names. + While old text terminals used to make 80 columns the standard, + these days, allowing 100 columns seems better, + since good style encourages the use of + descriptive variables and function names.

@@ -890,25 +921,31 @@ Robert Brown - You should use document strings to explain how to use your code. + You should use document strings on all visible functions + to explain how to use your code.

- You must comment anything complicated - so that the next developer can understand what's going on. - (Again, the "hit by a truck" principle.) + Unless some bit of code is painfully self-explanatory, + document it with a documentation string (also known as docstring).

- Unless some bit of code is painfully self-explanatory, document it. - Prefer documentation strings to comments - because the former can be displayed by programming tools, such as IDEs, + Documentation strings are destined to be read + by the programmers who use your code. + They can be extracted from functions, types, classes, variables and macros, + and displayed by programming tools, such as IDEs, or by REPL queries such as (describe 'foo); - they can also be extracted - to create web-based documentation or other reference works. + web-based documentation or other reference works + can be created based on them. + Documentation strings are thus the perfect locus to document your API. + They should describe how to use the code + (including what pitfalls to avoid), + as opposed to how the code works (and where more work is needed), + which is what you'll put in comments.

- Supply a documentation string (also known as docstring) when defining - top-level functions, types, classes, and macros. + Supply a documentation string when defining + top-level functions, types, classes, variables and macros. Generally, add a documentation string wherever the language allows.

@@ -934,9 +971,7 @@ Robert Brown nil) (t (loop for i from 3 upto (sqrt n) by 2 - do (when (divisorp i n) - (return-from small-prime-number-p nil))) - t))) + never (divisorp i n))))) (defgeneric table-clear (table) @@ -982,6 +1017,28 @@ Robert Brown You must use the appropriate number of semicolons to introduce comments. +

+ Comments are explanations to the future maintainers of the code. + Even if you're the only person who will ever see and touch the code, + even if you're either immortal and never going to quit, + or unconcerned with what happens after you leave + (and have your code self-destruct in such an eventuality), + you may find it useful to comment your code. + Indeed, by the time you revisit your code, + weeks, months or years later, + you will find yourself a different person from the one who wrote it, + and you will be grateful to that previous self + for making the code readable. +

+

+ You must comment anything complicated + so that the next developer can understand what's going on. + (Again, the "hit by a truck" principle.) +

+

+ Also use comments as a way to guide those who read the code, + so they know what to find where. +