[FAQ] How to code nicely


Global Moderator
This section is meant to give some general help, as proper coding is vital to good science practice. There are many of types of errors and inefficiency stemming from programming style (Kernighan & Plauger 1978). These bad practices are prolific and have even lead to retraction of publications (see e.g. Merali 2010). Below I supply some links, which may help you learn to code better and more efficiently. This is a small investment that should pay off big in the future, as bad coding practises once learnt are difficult to "unlearn".

For starters try some guides specific to R:

Daniel Falster's piece on writing nice R code

The Google R Style Guide

PLOS computation biology piece on efficient programming in R; Essentials of high performance computing

And finally find this best practices guide by Wilson et al 2012, a must read for aspiring programmers in science.

References on programming style:

Merali, Z. (2010) Computational science: Error, why scientific programming
does not compute. Nature, 467, 775–777.

Kernighan, B.W. & Plauger, P.J. (1978) The Elements of Programming Style.
McGraw Hill, New York, 2nd edition.

And lets not forget:
A guide for posting code on this forum.

Note to contributors: If you know of links to specific guides for your favourite programming language, please post them below!

If you're still having trouble with this topic feel free to start a thread on the forum, and be sure to check out our guidelines for efficient posting.
Last edited: