Abstraction
CL-HTTP is intended to be a toolkit for Web hacking. Although the ability to write
response functions in Common Lisp will increase productivity, it is helpful to have a
set of extensible abstractions to minimize code duplication and provide well-crafted
operators. Thus, the way Cl-HTTP can distinguish itself from other server offerings
will be by providing a rational set of abstractions or toolkit and making it easy to
extend or customize the behavior of the server.
Here are some hints about how to write well-abstracted code:
Use the existing operator.
Propose an extension to the existing operator.
Make a function or method do only one
well-defined task. The goal is to avoid repeating code fragments with close
functionality. Whenever a piece of code is used more than once, or is likely to
be used more than once, make it a first-class operator.
Give each operator, variable or class a
spelled-out mnemonic name so that others will find the abstraction and use it.
Recycle the vocabulary found in existing operators when naming new ones. Operators
should contain verb forms describing the action or function they do while arguments
should have names that describe the datatype which a caller should pass to them.
All external symbol and any major internal
operators should have document strings. These should explain what the operator does and
what its arguments are. As becomes obvious from the Online Help Facility the combination of the
documentation string with the function and argument names are the documentation.
When an operator gets too many parameterizing
arguments, consider breaking it up into subfunctions.
Whenever an operator's source definition
exceeds a screenful, break it down into a combination of suboperators.
Always use CLOS objects as
your datastructure. Forget about defstruct, except when speed is
essential!
Provide a generic function for each toplevel
operation on a class, while using functions or inline functions within according to
speed requirements.
Use local functions (e.g.,
FLET, LABELS, MACROLET) to capture abstractions within a definition and
to avoid repeated code.