[C/C++] Debating which language to choose

Dason

Ambassador to the humans
#1
Hi all,

I've got quite a bit of background in programming. A few semesters ago I took a course in 'Statistical Computing' and we worked with C in that class. C is ok but if you've ever dealt with it you know the frustrations that can come with it. The main reason why I would use C is to make calls to C functions that I've written to speed up some code. So I've been reteaching myself some C lately. The thing is that I've been hearing quite a bit about C++ and Rcpp. I've always been under the impression that C is faster code. It's closer to the machine. However what I've been reading lately seems to contradict that. Not that C++ will allow my stuff in R to be faster than C but that's it's comparable. And since it has better libraries to make your life easier you don't mess up when writing the code as much.

Of course with a more complex language there is more time you have to spend to learn it.

My question is if anybody has any opinion on this. Pretend that I don't have any C background and I'm debating whether to learn C or C++ where my goal is to interface with R.
 
#2
I prefer to use C in my interaction with R, mostly because R is itself written in C and uses C-like conventions, and because I find the C language and GCC compiler more simple than C++ and G++. If you plan to hack on R itself, go with C. That said, Rcpp has made writing R extensions in C++ really easy, and there are some great vignettes that introduce the package. If you already know C++, why not give Rcpp a try?

-Matt
 

Dason

Ambassador to the humans
#3
If you already know C++, why not give Rcpp a try?
I only know a tiny bit of C++. I've learned C in the past but I've forgotten quite a bit of it. I have most of the programs I've written to reteach myself but like I said I've been hearing good things about Rcpp so I considered just going that route instead. I probably won't do any hacking on R itself. My main goal is building packages so I know Rcpp is a viable option for that. I was just looking for extra input. Thanks!
 

Link

Ninja say what!?!
#4
I talked to my professor last semester when he was teaching C. His view is that C is a better language as well, though he could be a little bias since he learned how to program when C was popular. All his interfaced programs are written in C and taught to us in C.

Additionally, he feels that most libraries in C++ are just extensions written up C (at least the earlier versions of C++ were).

My view is if you want to make your life easier, and you are learning from scratch, go with C++. But if you are already familiar with C, I'd go with that.

Here's my professor's course public website: http://www.stat.berkeley.edu/classes/s243/

Hopefully, you'll find it useful. I learned a lot of good things from that class, and the course web site has a lot of examples and PDF explanations.