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