[R] Programming Concepts and Philosophy

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Jun 20 09:06:24 CEST 2008


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 (http://www.cc2e.com/) 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



More information about the R-help mailing list