From smckinney at bccrc.ca  Wed Feb 16 00:47:02 2011
From: smckinney at bccrc.ca (Steven McKinney)
Date: Tue, 15 Feb 2011 15:47:02 -0800
Subject: [Rd] Request: Suggestions for "good teaching" packages,
 esp. with C code
In-Reply-To: <20386_1297811446_1297811446_4D5B07E0.4020508@gmail.com>
References: <AANLkTikODppzk5=x7=TzVepH+aHuvaZUErf_0xQZ5ioX@mail.gmail.com>
	<4D5AF4A8.50001@auckland.ac.nz>
	<Pine.LNX.4.64.1102151353000.13921@cardinals.dreamhost.com>
	<AANLkTikn+t2V22x4bv1hg+1B7_WE7y3aPfS+MFMFwwRy@mail.gmail.com>
	<20386_1297811446_1297811446_4D5B07E0.4020508@gmail.com>
Message-ID: <DCE81E14EB74504B971DAD4D2DB0356B0864727E6A@crcmail4.BCCRC.CA>


> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf Of Duncan Murdoch
> Sent: February-15-11 3:10 PM
> To: Kevin Wright
> Cc: R Devel List
> Subject: Re: [Rd] Request: Suggestions for "good teaching" packages, esp. with C code
> 
> On 15/02/2011 5:22 PM, Kevin Wright wrote:
> > For those of you "familiar with R", here's a little quiz.  What what's the
> > difference between:
> >
> >
> > f1<- function(){
> >    a=5
> > }
> 
> This returns 5, invisibly.  It's also bad style, according to those of
> us who prefer <- to = for assignment.

For maximum clarity

f0 <- function() {
    b <- 5
    return( list( a = b ) )
}

> f0()
$a
[1] 5


Steven McKinney

> 
> > f2<- function(){
> >    return(a=5)
> > }
> 
> This is a mistake:  return() doesn't take named arguments.  It is
> lenient and lets you get away with this error (treating it the same as
> return(5)), and returns the 5, visibly.
> 
> Duncan Murdoch
> 
> > f2()
> >
> >
> > Kevin Wright
> >
> >
> >
> >
> > On Tue, Feb 15, 2011 at 3:55 PM, Geoff Jentry<geoffjentry at hexdump.org>wrote:
> >
> >> On Wed, 16 Feb 2011, David Scott wrote:
> >>
> >>> 4. We don't want gratuitous use of "return" at the end of functions.
> >>>> Why do people still do that?
> >>>>
> >>> Well I for one (and Jeff as well it seems) think it is good programming
> >>> practice. It makes explicit what is being returned eliminating the
> >>> possibility of mistakes and provides clarity for anyone reading the code.
> >>>
> >>
> >> You're unnecessarily adding the overhead of a function call by explicitly
> >> calling return().
> >>
> >> Sure it seems odd for someone coming from the C/C++/Java/etc world, but
> >> anyone familiar with R should find code that doesn't have an explicit
> >> return() call to be fully readable&  clear.
> >>
> >> -J
> >>
> >>
> >> ______________________________________________
> >> R-devel at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-devel
> >>
> >
> > 	[[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Request: Suggestions for "good teaching" packages, esp. with C code
Steven McKinney