[Rd] question

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Sat Mar 7 23:28:32 CET 2009


Thomas Petzoldt wrote:
> Patrick Burns wrote:
>> One idea of program design is that users
>> should be protected against themselves.

... and r coherently implements this idea :]

>>
>> It is my experience that users, especially
>> novices, tend to over-split items rather than
>> over-clump items.  The fact that items are
>> returned by the same function call would
>> argue to me that there is a connection between
>> the items.
>>
>>
>> Patrick Burns
>> patrick at burns-stat.com
>> +44 (0)20 8525 0696
>> http://www.burns-stat.com
>> (home of "The R Inferno" and "A Guide for the Unwilling S User")
>
> Hi Gabor, Patrick, Ivo and vQ,

hello thomas,

>
> I agree with Patrick and Gabor that it is not needed. IMHO it is good
> design that a function (in a mathematical sense) returns ONE object,
> let it a single value, a list or an S3/S4 object. 

in r functions are not functions in the mathematical sense.  r is not
quite a functional programming language, though it's certainly closer to
fp than c or fortran, say.

if one were really interested in whether the feature is desired as a
convenience rather than in enforcing one's own opinion, one'd ask
users.  it's certainly not *needed* in the sense that you can do without
it -- but then there are many more features in r which are not needed
(and some of them are more harmful than multiple return values would be).


> This can be passed to another function as a whole or can be splitted
> to its parts according to different needs. 

right, but that's extra work with coding and performance penalty. 

> If only single parts are required, than I would suggest to use
> accessor functions preferably written as generics working on returned
> S3 or S4 objects. I'm strongly against going back to the past S
> behaviour and I wonder a little bit about this discussion. 

i don't know that s behaviour, it's quite possible that it was really
wrong.  but the fact that s had it wrong (if it did) does not mean that
multiple return values are wrong per se.

> I like it to have a clean workspace with only a few objects.

why would letting others choose for themselves be a bad idea?  that's
what perl, python, ruby, or more recent languages such as scala, do --
functions can return (tuples of) multiple values which you can capture
separately and/or collectively.  multiple assignment is a fairly common
feature in modern programming languages.

it seems that this is a remote dream in r, because 'users should be
protected against themselves'.

vQ



More information about the R-devel mailing list