In which order should code in a single lisp file be organised? Is there any common style guideline that allows other lisp programmers to easily understand code?
Googling for lisp style guideline yields plenty results; among them:
- Common Lisp Style Guide by Google
- Community-driven Emacs Lisp style Guide by Bozhidar Batsov, contains details about formatting, indentation, sapces versus tabs.
- Tutorial on Good Lisp Programming Style by Peter Norvig and Kent Pitman, details the reasoning behind adhering to a style and the rationale for making certain choices.
However, non appear to discuss how functions and other definitions should be organised within a single source file.
"Clean Code" by Martin Fowler (which is not specifically targeted at Lisp) recommends organising functions/methods top to bottom: first describing the code abstractly and next delving deeper and deeper into details. Which is in my opinion a good way to organise function definitions.
However, when the function definitions are ordered top to bottom, the SBCL REPL gives caught STYLE-WARNING: undefined function: …
when loading a lisp file. So apparently SBCL thinks using a function before defining it is bad style.
What is the best practice for the order of definitions? Preferably without resulting in compiler/interpreter warnings.
labels
or declare my functions before defining them withdeclaim
.