Changeset 184
- Timestamp:
- Jan 24, 2008, 3:53:01 PM (18 years ago)
- Author:
- neil.c.c.brown
- Message:
-
Added to the section on coding standards
- File:
-
- 1 edited
- docs/trunk/hacking-guide/tock-intro.tex (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/trunk/hacking-guide/tock-intro.tex
r183 r184 359 359 code would be faster. The compiler does not have to be blindingly fast, but it does need to be 360 360 maintainable. 361 \item If a function foo is specifically needed by only the function bar, place foo inside the (削除) where (削除ここまで)361 \item If a function foo is specifically needed by only the function bar, place foo inside the (追記) \lstinline|where| (追記ここまで) 362 362 clause of bar (unless this is particularly untenable). This keeps the code neater, and foo can always 363 363 be moved to the top-level later if necessary. 364 \item Try to provide type signatures for every function (i.e. anything of (削除) type a -> b -> c) in a where clause. (削除ここまで)365 (削除) Providing types for values in where clauses (削除ここまで)is also never a bad thing.364 \item Try to provide type signatures for every function (i.e. anything of (追記) kind \lstinline|* -> *|) in a (追記ここまで) 365 (追記) \lstinline|where| clause. Providing types for values in where \lstinline|clauses| (追記ここまで) is also never a bad thing. 366 366 \item Favour map, zip, etc over list comprehensions; it is usually neater. 367 (追記) \item Try not to leave warnings in the code. We have compiler options turned on to generate various warnings. (追記ここまで) 368 (追記) Defaulting-to-type warnings can be solved by inserting a type signature, and unused binding warnings can (追記ここまで) 369 (追記) be solved by removing the unused function, unless you know the lack of used is temporary. (追記ここまで) 367 370 \item Never allow any possibility of a non-graceful run-time error. For example, do not use head, which 368 can fail directly with a non-helpful error message. Instead, use a (削除) case statement (with a pattern-match), (削除ここまで)369 and in the case where the list is empty, use the die/dieP/dieInternal functions to provide a more helpful 370 (削除) (削除ここまで)error message (such as ``list of types was not expected to be empty in function foo''). This is for371 can fail directly with a non-helpful error message. Instead, use a (追記) \lstinline|case| statement (with a (追記ここまで) 372 pattern-match), and in the case where the list is empty, use the die/dieP/dieInternal functions to provide a 373 (追記) more helpful (追記ここまで)error message (such as ``list of types was not expected to be empty in function foo''). This is for 371 374 practical reasons; if we used head everywhere in the code, then when the program failed with ``head: empty list'' 372 375 it would be very hard to work out exactly which instance of head had given the error. Similarly, try to … … 374 377 then gives an error message. Although this is not quite as crucial, because at least the error message 375 378 for a failed pattern match gives the relevant line numbers. 379 (追記) \item In lists where order is unimportant (such as test lists, or module import lists), maintain (追記ここまで) 380 (追記) alphabetical order (to make it easier to find items in a long list). (追記ここまで) 381 (追記) \item When writing out lists or tuples on one line, make sure there is a space after the comma (clearer, (追記ここまで) 382 (追記) and Adam's preference). (追記ここまで) 383 (追記) \item When writing out lists on several lines, put the commas between items at the beginning of each line, (追記ここまで) 384 (追記) not at the end (can make patches clearer by not disrupting surrounding lines and Neil's preference). (追記ここまで) 376 385 \end{enumerate} 377 386
Note:
See TracChangeset
for help on using the changeset viewer.