[Rd] C vs. C++ as learning and development tool for R
murdoch at stats.uwo.ca
Fri Jan 19 14:51:14 CET 2007
On 1/19/2007 3:55 AM, Kimpel, Mark William wrote:
> I have 3 years of experience with R and have an interest in becoming a
> better programmer so that I might someday be able to contribute
> packages. Other than R, my only experience was taking Lisp from Daniel
> Friedman in the 1970's. I would like to learn either C or C++ for
> several reasons:
> To gain a better concept of object oriented programming so that I can
> begin to use S4 methods in R.
> To perhaps speed up some things I do repeatedly in R
> To be able to contribute a package someday.
> I have been doing some reading and from what I can tell R is more
> compatible with C, but C++ has much greater capabilities for OO
> I have just started reading The C++ Programming Language: Special
> Edition by Bjarne Stroustrup
> ustrup&z=y> , he recommends first learning C++ and then then C if
> necessary, but as a developer of C++, he is probably biased.
> I would greatly appreciate the advice of the R developers and package
> contributors on this subject. "C" or "C++"?
For your purposes, I would recommend C. Most example code you'll find
is written in C, so it's easier to learn by looking at simple examples
written by others. The R external interface was designed with C in
mind, so you need to tell C++ to act like C to use it.
Regarding OOP, I think the C++ style of OOP is so different from S4 that
it would not actually be helpful in learning S4. As far as I know, none
of the languages that are easy to link to R use the same style of OOP.
On the other hand, taking a disciplined approach to C programming is a
good idea (which is I think what Stroustrup had in mind). I'd suggest
an object oriented Pascal (e.g. Delphi) or Java if that's what you want,
because they are simpler than C++. C and R are very permissive
languages, and if you take advantage of that you can write amazingly
sloppy and unmaintainable code.
More information about the R-devel