Lisp is one of the oldest high-level programming languages, known for its distinctive fully parenthesized prefix notation and its treatment of code as data. It has influenced many languages and is still used in various dialects such as Common Lisp, Scheme, and Clojure.
Lisp Anti-Patterns Overview
Excessive Global Variables
Improper Error Handling
ignore-errors
unless you have a good reason. Instead, use handler-case
to catch specific conditions and handle them appropriately. For more complex error recovery, use Common Lisp’s powerful condition system with restart-case
to provide multiple recovery strategies.Reinventing Built-in Functions
Excessive Recursion Without Tail Calls
Excessive Use of EVAL
eval
for runtime code execution. eval
is powerful but dangerous, as it can execute arbitrary code and makes your program harder to analyze and optimize. Instead, use funcall
or apply
to call functions dynamically.Not Using CLOS Effectively
Improper Use of Macros
gensym
or with-gensyms
.Not Using Loop Abstraction
map
, reduce
, remove-if
, or the loop
macro instead of writing low-level iteration code. These abstractions make your code more declarative and often more concise.Excessive Side Effects
Not Using Packages Properly
Improper List Manipulation
Not Using Format Properly
format
function for formatted output instead of concatenating strings or using multiple print statements. format
provides a powerful mini-language for controlling output formatting.Not Using Loop Invariants
Not Using Destructuring
destructuring-bind
, multiple-value-bind
, and pattern matching in macros like loop
and iterate
.Not Using Documentation Strings
documentation
.Not Writing Tests
Not Using Proper Naming Conventions
*earmuffs*
for special variables and +plus-signs+
for constants. Consistent naming makes your code more readable and idiomatic.