85 lines
No EOL
5.7 KiB
HTML
85 lines
No EOL
5.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<title>CLiki: Programming style</title>
|
|
<link rel="alternate" type="application/atom+xml" title="ATOM feed of edits to current article"
|
|
href="https://www.cliki.net/site/feed/article.atom?title=Programming%20style">
|
|
<link rel="stylesheet" href="static/css/style.css">
|
|
<link rel="stylesheet" href="static/css/colorize.css">
|
|
</head>
|
|
|
|
<body>
|
|
<span class="hidden">CLiki - Programming style</span>
|
|
<div id="content"><div id="content-area"><div id="article-title">Programming style</div><div id="article">These are suggestions for programming style, some undisputable, some my (Stanisław Halik) whims.<p><ul>
|
|
<li>Always put parenthesis after the previous expression on its line, never on a line by itself. If you have trouble reading code formatted in this way, ignore the parens (or make them disappear by regexp-replace or font lock) and look at indentation.</li><p><li> Use long, descriptive variable names. It's <tt>+buffer-size+</tt>, not <tt>+BUFSIZ+</tt> or similar. This immensely helps reading comprehension and generally alleviates the need to comment the code (see below). I can't bring myself to read uncommented code in languages that don't allow hyphens in variable names, while I can read people's Lisp just fine. It doesn't apply when abbreviations are widely known (e.g.<tt>retval</tt>, <tt>i</tt>). Also abbreviate extremely long symbol names, e.g. <tt>frobnicate-svuc</tt> might be preferred to <tt>frobnicate-slot-value-using-class</tt> if the code is expected to fit in 80 columns.</li><p><li>Comment non-obvious stuff. For instance, once I wrote the following code:<p><pre class="inline">(defmacro fn (&environment env &body body)
|
|
(with-walker-configuration (:undefined-reference-handler nil)
|
|
;; .VARS is modified implicitly in macroexpansion of the form
|
|
;; package protects against leaking symbols
|
|
(let* ((.vars nil)
|
|
(macro-name (gensym))
|
|
(ret (macroexpand-all `(macrolet ((,macro-name ()
|
|
(car (push (gensym) .vars))))
|
|
(symbol-macrolet ((_ (,macro-name)))
|
|
(progn . ,body)))
|
|
env)))
|
|
(declare (special .vars))
|
|
`(lambda ,(reverse .vars)
|
|
,ret))))</pre><p>and had to add the comment because it wasn't immediately obvious what this code does.</li><p><li>Instead of <tt>(if some-list .. ...)</tt> use <tt>(if (not (endp some-list)) ... ...)</tt>. Instead of <tt>(if (lookup foo) ... ...)</tt> use <tt>(if (not (null (lookup foo))) ... ...)</tt>. Basically, only use a bare expression in conditionals if it uses the -p convention.
|
|
</li>
|
|
</ul>
|
|
<h2>Other Style Guides</h2><p><ul>
|
|
<li>
|
|
<a href="http://www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf">Norvig's Tutorial on Good Lisp Programming Style (PDF)</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://mumble.net/~campbell/scheme/style.txt">Riastradh's Lisp Style Rules (TXT)</a>
|
|
</li>
|
|
<li>
|
|
<a href="http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part1/faq-doc-4.html">FAQ: How can I improve my Lisp programming style and coding efficiency?</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://www.cs.utexas.edu/users/novak/lispeff.html">Novak's Lisp Style and Efficiency</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://courses.cs.northwestern.edu/325/readings/lisp-style.php">Chris Riesbeck's EECS 325 Lisp Style</a>
|
|
</li>
|
|
</ul><p><hr>
|
|
<a href="document.html" class="category">document</a> <a href="macro example.html" class="category">macro example</a></div></div>
|
|
<div id="footer" class="buttonbar"><ul><li><a href="Programming style.html">Current version</a></li>
|
|
<li><a href="https://www.cliki.net/site/history?article=Programming%20style">History</a></li>
|
|
<li><a href="https://www.cliki.net/site/backlinks?article=Programming%20style">Backlinks</a></li><li><a href="https://www.cliki.net/site/edit-article?title=Programming%20style&from-revision=3800126446">Edit</a></li><li><a href="https://www.cliki.net/site/edit-article?create=t">Create</a></li></ul></div>
|
|
</div>
|
|
<div id="header-buttons" class="buttonbar">
|
|
<ul>
|
|
<li><a href="https://www.cliki.net/">Home</a></li>
|
|
<li><a href="https://www.cliki.net/site/recent-changes">Recent Changes</a></li>
|
|
<li><a href="CLiki.html">About</a></li>
|
|
<li><a href="Text Formatting.html">Text Formatting</a></li>
|
|
<li><a href="https://www.cliki.net/site/tools">Tools</a></li>
|
|
</ul>
|
|
<div id="search">
|
|
<form action="https://www.cliki.net/site/search">
|
|
<label for="search_query" class="hidden">Search CLiki</label>
|
|
<input type="text" name="query" id="search_query" value="" />
|
|
<input type="submit" value="search" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<div id="pageheader">
|
|
<div id="header">
|
|
<span id="logo">CLiki</span>
|
|
<span id="slogan">the common lisp wiki</span>
|
|
<div id="login"><form method="post" action="https://www.cliki.net/site/login">
|
|
<label for="login_name" class="hidden">Account name</label>
|
|
<input type="text" name="name" id="login_name" class="login_input" />
|
|
<label for= "login_password" class="hidden">Password</label>
|
|
<input type="password" name="password" id="login_password" class="login_input" />
|
|
<input type="submit" name="login" value="login" id="login_submit" /><br />
|
|
<div id="register"><a href="https://www.cliki.net/site/register">register</a></div>
|
|
<input type="submit" name="reset-pw" value="reset password" id="reset_pw" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body></html> |