Coding Standards for Biostat 778
- Program files should _always_ be ASCII text files. Program files should always be immediately source-able into R or read by a C compiler in the case of C programs. If you cannot source your file directly into R, then the file format is not acceptable. Word processing programs like Microsoft Word, by default, do not save files as text files.
- Always use a monospace font to write any code. Variable space fonts like Times New Roman or Charter or Georgia are not appropriate and can alter the apparent structure of a program (and hence its readability).
- Always indent your code. If you use an editor like GNU
Emacs, then there is support for automatic indentation of
code. Indentations should be 8 spaces wide or a tab whose
length is equal to 8 spaces (this is often _not_ the default
for many editors). Comments should be indented to the same
level of indentation of the code to which the comment
pertains. Comments can also appear at the end of a code line,
if space permits (see below).
If you use Emacs as your text editor and ESS for editing R code, you can use the following in your .emacs file to get 8-spaces tab indents:
;; ESS (add-hook 'ess-mode-hook (lambda () (ess-set-style 'BSD) (setq tab-width 8) (setq indent-tabs-mode t)))
- Your code should not extend past 80 columns. This is because standard Unix terminal windows are 80 columns wide and if your code wraps around the end of the line it becomes very annoying to read. Set your editor to 80 columns wide and don't go over it. Break long lines if you have to. Exceptions can be made only for hard-coded constants (such as path names or URLs) which cannot easily be wrapped or shortened.