[Rcpp-devel] Parameter Naming (was: Speed gain assistance)
Dirk Eddelbuettel
edd at debian.org
Thu Aug 18 15:44:49 CEST 2011
On 18 August 2011 at 16:24, Darren Cook wrote:
| I'd like to shamelessly hijack Christopher Wray's question to ask if
| there is a convention for parameter naming with Rcpp and inline. Well,
| actually I'll propose one, to then see what others prefer.
|
| First I would propose to use long variable names, instead of
| abbreviations, in both the CPP and R sides [1]. I already know enough R
| to know this will be immediately rejected ;-) [2]
|
| Anyway, while trying to understand the posted code I found myself
| jumping back and forth between the below two blocks of code, muttering
| to myself, "so the bottleneck is proportional to 2nd parameter which is
| SamSize, which is then called SS_C, ..."
|
| > src<-'
| > NumericVector RetIn(RetVec);
| > int SS_C=as<int>(SamSize);
| > double St_C=as<double>(StM);
| > int ES_C=as<int>(ExpSize);
| > ...
| > sscpp2<-cfunction(
| > signature(RetVec="numericVector",SamSize="numeric",StM="numeric",ExpSize="numeric"),
| > src,inc, Rcpp=TRUE,cppargs="",convention=".Call")
|
| So, my proposal would be to use the same names in the signature that you
| intend to use in the C++ code, but with underline appended. I.e.
You must do that anyway or you get linking errors.
The rest is stylistic, and we do not impose a style (besides maybe the
default indentation I get from Emacs :). If you need a style, I suggest to
follow R conventions as layed out in the R Internals manual. Personally, I
also like this one:
http://quantlib.org/style.shtml
Descriptive names are good, comments are good, using separate names for
members vars is good and I still mostly prepend m_.
Dirk
| signature(RetIn_="numericVector",SS_C_="numeric",St_C_="numeric",ES_C_="numeric")
|
| The C++ code then starts:
| NumericVector RetIn(RetIn_);
| int SS_C=as<int>(SS_C_);
| double St_C=as<double>(St_C_);
| int ES_C=as<int>(ES_C);
|
| What conventions are other people using?
|
| Darren
|
| [1]: I am not alone in this. E.g. see "Rename Method" in Martin Fowler's
| Refactoring; "It's All Writing" in The Pragmatic Programmer (ch.8); etc.
|
| [2]: I realize many R functions are direct translations of mathematical
| functions, so calling a parameter "p" is not as meaningless as it
| appears at first glance. I still think it should be "probabilities" not
| "p" (yes, "qunif", I'm looking at you), but I realize I'm in a minority
| when surrounded byq mathematicians.
|
|
|
|
| --
| Darren Cook, Software Researcher/Developer
|
| http://dcook.org/work/ (About me and my work)
| http://dcook.org/blogs.html (My blogs and articles)
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Two new Rcpp master classes for R and C++ integration scheduled for
New York (Sep 24) and San Francisco (Oct 8), more details are at
http://dirk.eddelbuettel.com/blog/2011/08/04#rcpp_classes_2011-09_and_2011-10
http://www.revolutionanalytics.com/products/training/public/rcpp-master-class.php
More information about the Rcpp-devel
mailing list