Re: [R] Programming Concepts and Philosophy

From: Jan T. Kim <jtk_at_cmp.uea.ac.uk>
Date: Fri, 20 Jun 2008 11:13:47 +0100

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  >=-----*

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 20 Jun 2008 - 10:27:12 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 - 13:30:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive