[R] Programming Concepts and Philosophy

Jan T. Kim jtk at cmp.uea.ac.uk
Fri Jun 20 12:13:47 CEST 2008


On Fri, Jun 20, 2008 at 09:06:24AM +0200, Wacek Kusnierczyk wrote:
> 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. 

Not necessarily -- R's "promise" mechanism quite reasonably ensures
that copies of parameter objects are only made upon modifying these
objects.

However, on a more fundamental "programming philosophy" note, the fact
that R does not allow multiple references to one object is a limitation.
One of the fundamental principles of good programming is that there
should be a one-to-one correspondence between instances in the program
and objects in the "real world" (problem domain etc.), and having no
references makes achieving this difficult (and quite impossible for
more complex systems).

Best regards, Jan
-- 
 +- Jan T. Kim -------------------------------------------------------+
 |             email: jtk at cmp.uea.ac.uk                               |
 |             WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*



More information about the R-help mailing list