Kimpel, Mark William
2007-Jan-19 08:55 UTC
[Rd] C vs. C++ as learning and development tool for R
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 programming. I have just started reading The C++ Programming Language: Special Edition by Bjarne Stroustrup <http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro 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++"? Thanks, Mark Mark W. Kimpel MD Official Business Address: Department of Psychiatry Indiana University School of Medicine PR M116 Institute of Psychiatric Research 791 Union Drive Indianapolis, IN 46202 Preferred Mailing Address: 15032 Hunter Court Westfield, IN 46074 (317) 490-5129 Work, & Mobile (317) 663-0513 Home (no voice mail please) 1-(317)-536-2730 FAX [[alternative HTML version deleted]]
Duncan Murdoch
2007-Jan-19 13:51 UTC
[Rd] C vs. C++ as learning and development tool for R
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 > programming. > > > > I have just started reading The C++ Programming Language: Special > Edition by Bjarne Stroustrup > <http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro > 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. Duncan Murdoch
Gabor Grothendieck
2007-Jan-19 13:53 UTC
[Rd] C vs. C++ as learning and development tool for R
You don't necessarily need to know C or C++ to write an R package. Many (maybe most) R packages only use R. On 1/19/07, Kimpel, Mark William <mkimpel at iupui.edu> 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 > programming. > > > > I have just started reading The C++ Programming Language: Special > Edition by Bjarne Stroustrup > <http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro > 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++"? > > > > Thanks, > > > > Mark > > > > Mark W. Kimpel MD > > > > > > Official Business Address: > > > > Department of Psychiatry > > Indiana University School of Medicine > > PR M116 > > Institute of Psychiatric Research > > 791 Union Drive > > Indianapolis, IN 46202 > > > > Preferred Mailing Address: > > > > 15032 Hunter Court > > Westfield, IN 46074 > > > > (317) 490-5129 Work, & Mobile > > > > (317) 663-0513 Home (no voice mail please) > > 1-(317)-536-2730 FAX > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Ramon Diaz-Uriarte
2007-Jan-19 14:03 UTC
[Rd] C vs. C++ as learning and development tool for R
Dear Mark, On Friday 19 January 2007 09:55, 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. >I do not think C++ is the best idea if you are learning it to understand the OOP of R. The OOP of R is probably closer to that of CLOS (the common lisp object system) than C++ and Java. It might be better to directly go ahead and look for documentation specificaly about R's OOP.> 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 > programming. > > > > I have just started reading The C++ Programming Language: Special > Edition by Bjarne Stroustrup > <http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro > 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++"? > >I'd recommend C instead of C++: C++ is a huge language and it is somewhat easier to interface C than C++ from R. (In "non-R" stuff I prefer to use C++ better than C, even if just as in "C++as a better C", but this probably is not a reasonable reason to learn C++). HTH, R.> > Thanks, > > > > Mark > > > > Mark W. Kimpel MD > > > > > > Official Business Address: > > > > Department of Psychiatry > > Indiana University School of Medicine > > PR M116 > > Institute of Psychiatric Research > > 791 Union Drive > > Indianapolis, IN 46202 > > > > Preferred Mailing Address: > > > > 15032 Hunter Court > > Westfield, IN 46074 > > > > (317) 490-5129 Work, & Mobile > > > > (317) 663-0513 Home (no voice mail please) > > 1-(317)-536-2730 FAX > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Ram?n D?az-Uriarte Centro Nacional de Investigaciones Oncol?gicas (CNIO) (Spanish National Cancer Center) Melchor Fern?ndez Almagro, 3 28029 Madrid (Spain) Fax: +-34-91-224-6972 Phone: +-34-91-224-6900 http://ligarto.org/rdiaz PGP KeyID: 0xE89B3462 (http://ligarto.org/rdiaz/0xE89B3462.asc) **NOTA DE CONFIDENCIALIDAD** Este correo electr?nico, y en s...{{dropped}}
Dominick Samperi
2007-Jan-19 18:21 UTC
[Rd] C vs. C++ as learning and development tool for R
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. >If you decide to use C++ with R you should check out the documentation that comes with the package RcppTemplate, and the sample code that comes with that package. In my experience C++ (or C or FORTRAN) is needed for many compute intensive tasks, and the R framework provides a nice front-end with its extensive collection of visualization and statistical analysis tools. Disclaimer: I have no experience with S4. ds
On Fri, Jan 19, 2007 at 03:55:30AM -0500, 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 > programming. > > > > I have just started reading The C++ Programming Language: Special > Edition by Bjarne Stroustrup > <http://search.barnesandnoble.com/booksearch/results.asp?ATH=Bjarne+Stro > 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++"? >To echo several other comments, if your goal is to work in R, it would be best to go straight to R. I haven't used lisp much, but I believe it is much closer to R than most other languages you could pick. It has a functional style, and I recall reading the R's scoping rules were directly inspired by Scheme, a Lisp variant. In fact, I didn't feel I fully grasped them until I looked at Abelson and Sussman's "Structure and Interpretation of Computer Languages" (which uses Scheme). The "functional" OO of R is significantly different from the "class-based" OO found in most languages calling themselves object oriented, including C++, Java, Python and smalltalk. Learning those other languages to understand R could actually interfere with learning R. If and when you need speed, you can program in any language that supports Fortran or C interfaces, which is almost all of them. If you're just doing general education.... I use C++ in R, and I have to say that programming in C++ is a wretched experience. You have to make a major committment to learning the language, which is a minefield of gotcha's, to use it in full OO style. As others on this list and Stroustrup suggest, you can use it and just incrementally add features over what you would do in C. It can also be speedy and powerful (to run, not to program in!), which is why I'm using it. For pure OO, I think you can't beat smalltalk, which is freely available at www.squeak.org (also there is a GNU and several commerical versions). The language rules and syntax fit on one page. The catch is that to use it you need to learn the environment and the class library; these too are big tasks. Objective-C is a much more lightweight C'ish OO than C++ (the author moved smalltalk concepts into C). It's available as part of the GNU compilers. Unlike smalltalk, you might use it if you cared about performance, and it's the native language of Mac OS-X. It has a relatively small learning curve. Python and Java are other choices for OO, both significantly simpler than C++. I find Python to be simple and elegant; it's also nifty for scripting random tasks. Java's widely used on the web and in the enterprise. Eiffel is also interesting. I can't say much about "libraries already on other machines", but the C runtime is probably the one you can count on being there the most. Of course, another route would be to explore other functional languages, a terrain I barely know: Haskell, ML, OCaml... In particular, some of them have lazy evaluation of arguments, which R also employs. And there are the functional/object languages like CLOS (I think the O in OCaml is Object). Anyway, this risks becoming a general language thread. My main point, as someone who's been there, is don't use C++ unless you have a compelling reason and a lot of time! Ross Boylan (Among the languages listed, the ones I've used extensively are C, C++, Objective-C, Python, R, and smalltalk.)