18537
|
1 |
|
18538
|
2 |
(* $Id$ *)
|
|
3 |
|
|
4 |
theory "ML" imports base begin
|
|
5 |
|
|
6 |
chapter {* Aesthetics of ML programming *}
|
|
7 |
|
21148
|
8 |
text {* This style guide is loosely based on
|
|
9 |
\url{http://caml.inria.fr/resources/doc/guides/guidelines.en.html}.
|
|
10 |
% FIMXE \url{http://www.cs.cornell.edu/Courses/cs312/2003sp/handouts/style.htm}
|
|
11 |
|
|
12 |
Like any style guide, it should not be interpreted dogmatically.
|
|
13 |
Instead, it forms a collection of recommendations which,
|
|
14 |
if obeyed, result in code that is not considered to be
|
|
15 |
obfuscated. In certain cases, derivations are encouraged,
|
|
16 |
as far as you know what you are doing.
|
|
17 |
|
|
18 |
\begin{description}
|
|
19 |
|
|
20 |
\item[fundamental law of programming]
|
|
21 |
Whenever writing code, keep in mind: A program is
|
|
22 |
written once, modified ten times, and read
|
|
23 |
100 times. So simplify its writing,
|
|
24 |
always keep future modifications in mind,
|
|
25 |
and never jeopardize readability. Every second you hesitate
|
|
26 |
to spend on making your code more clear you will
|
|
27 |
have to spend ten times understanding what you have
|
|
28 |
written later on.
|
|
29 |
|
|
30 |
\item[white space matters]
|
|
31 |
Treat white space in your code as if it determines
|
|
32 |
the meaning of code.
|
|
33 |
|
|
34 |
\begin{itemize}
|
|
35 |
|
|
36 |
\item The space bar is the easiest key to find on the keyboard,
|
|
37 |
press it as often as necessary. {\ttfamily 2 + 2} is better
|
|
38 |
than {\ttfamily 2+2}, likewise {\ttfamily f (x, y)}
|
|
39 |
better than {\ttfamily f(x,y)}.
|
|
40 |
|
|
41 |
\item Restrict your lines to \emph{at most} 80 characters.
|
|
42 |
This will allow you to keep the beginning of a line
|
|
43 |
in view while watching its end.
|
|
44 |
|
|
45 |
\item Ban tabs; they are a context-sensitive formatting
|
|
46 |
feature and likely to confuse anyone not using your
|
|
47 |
favourite editor.
|
|
48 |
|
|
49 |
\item Get rid of trailing whitespace. Instead, do not
|
|
50 |
surpess a trailing newline at the end of your files.
|
|
51 |
|
|
52 |
\item Choose a generally accepted style of indentation,
|
|
53 |
then use it systematically throughout the whole
|
|
54 |
application. An indentation of two spaces is appropriate.
|
|
55 |
Avoid dangling indentation.
|
|
56 |
|
|
57 |
\end{itemize}
|
|
58 |
|
|
59 |
\item[cut-and-paste succeeds over copy-and-paste]
|
|
60 |
\emph{Never} copy-and-paste code when programming. If you
|
|
61 |
need the same piece of code twice, introduce a
|
|
62 |
reasonable auxiliary function (if there is no
|
|
63 |
such function, very likely you got something wrong).
|
|
64 |
Any copy-and-paste will turn out to be painful
|
|
65 |
when something has to be changed or fixed later on.
|
|
66 |
|
|
67 |
\item[comments]
|
|
68 |
are a device which requires careful thinking before using
|
|
69 |
it. The best comment for your code should be the code itself.
|
|
70 |
Prefer efforts to write clear, understandable code
|
|
71 |
over efforts to explain nasty code.
|
|
72 |
|
|
73 |
\item[functional programming is based on functions]
|
|
74 |
Avoid ``constructivisms'', e.g. pass a table lookup function,
|
|
75 |
rather than an actual table with lookup in body. Accustom
|
|
76 |
your way of codeing to the level of expressiveness
|
|
77 |
a functional programming language is giving onto you.
|
|
78 |
|
|
79 |
\item[tuples]
|
|
80 |
are often in the way. When there is no striking argument
|
|
81 |
to tuple function arguments, just write your function curried.
|
|
82 |
|
|
83 |
\item[telling names]
|
|
84 |
Any name should tell its purpose as exactly as possible,
|
|
85 |
while keeping its length to the absolutely neccessary minimum.
|
|
86 |
Always give the same name to function arguments which
|
|
87 |
have the same meaning. Separate words by underscores
|
|
88 |
(``{\ttfamily int\_of\_string}'', not ``{\ttfamily intOfString}'')
|
|
89 |
|
|
90 |
\end{description}
|
18554
|
91 |
*}
|
18538
|
92 |
|
|
93 |
|
|
94 |
chapter {* Basic library functions *}
|
|
95 |
|
20520
|
96 |
text {* FIXME beyond the NJ basis library proposal *}
|
18538
|
97 |
|
20489
|
98 |
|
|
99 |
chapter {* Cookbook *}
|
|
100 |
|
20491
|
101 |
section {* A method that depends on declarations in the context *}
|
20489
|
102 |
|
|
103 |
text FIXME
|
|
104 |
|
18538
|
105 |
end
|