Re: [R] Programming Concepts and Philosophy

From: Simon Blomberg <>
Date: Fri, 20 Jun 2008 14:57:39 +1000

I try to use a functional programming style. I define functions within functions when it is helpful in terms of information hiding. I avoid writing functions with side-effects as much as possible, so the only communication of the called function with the caller function is through the arguments and the returned value. I try to keep the code as simple and clear as possible (this is one of the things I fail at most). An appropriate amount of comments is also useful, especially when returning to old code after a long break. OOP is useful for really big projects, but I find OOP unnecessarily complicated for small jobs.

I found "Code Complete", by McConnell ( to be very helpful. I'm sure there are other books around with similar tips. Before I switched to R, I used XLisp-Stat. I found learning Lisp to be a really good way to learn good programming practices. Good Lisp code is the closest thing you can get to poetry in computer programming. "Lisp Style & Design", by Miller and Benson was helpful. I'd like to see an "S Style & Design."



On Fri, 2008-06-20 at 14:35 +1200, Murray Jorgensen wrote:
> I am wondering if people on the list could recommend books that they
> have found helpful about programming concepts and style? I often find
> that students write R programs by copying existing code but could really
> benefit from the understanding of more general programming ideas. An
> example would be to avoid writing functions which attempt to modify
> their parameters. Another principle would be not to write programs with
> numbers used as constants but to assign them to named objects as in
> n <- 120 # number of observations
> p <- 10 # number of variables
> near the beginning of a program rather than using "10" and "120"
> throughout the script.
> This sort of stuff is not specifically R but can be a problem for
> students with little programming background.
> I am happy to summarise responses.
> Murray Jorgensen

Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
Faculty of Biological and Chemical Sciences 
The University of Queensland 
St. Lucia Queensland 4072 
Room 320 Goddard Building (8)
T: +61 7 3365 2506

1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer can 
be extracted from a given body of data. - John Tukey.

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 20 Jun 2008 - 06:44:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 20 Jun 2008 - 10:30:45 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive