Re: [R] Programming Concepts and Philosophy

From: Wacek Kusnierczyk <>
Date: Fri, 20 Jun 2008 09:06:24 +0200

Simon Blomberg wrote:
> 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."

i support this view. i found sicp (structure and interpretation of computer programs, by abelson & sussman, a real classic in the field) particularly enlightening, although it certainly is a bit outdated in many respects -- but just a bit. functional programming style is great, but beware -- r will create (afaik, experts please correct me if this is wrong) a deep copy of about any object you send as an argument to a function (if only when it is actually used inside the function), and the result may be that the more beautiful the code, the more the performance sucks.

in pure functional programming, a function cannot change any part of the object passed to it as an argument, so there's no need for making a local copy. in r everything can happen as you can deparse the call to a function inside the function body, and you can never tell whether the object you pass to a function will be changed or not, given only the function's signature.

vQ mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 20 Jun 2008 - 09:37:57 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 - 17:30:48 GMT.

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

list of date sections of archive