[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Intensive computing: Ruby? Ruby/C? Pure C++?

M. Edward (Ed) Borasky

1/17/2007 3:27:00 PM

Shot (Piotr Szotkowski) wrote:
> Hello, ruby-talk. I have a question about choosing between Ruby, Ruby
> with C extensions (InlineRuby, ruby2c, etc.) and pure C++. I'll try to
> keep it short and to the point; thanks in advance for any answers, and
> of course I'm more than happy to clarify/extend the below if needed.
>
> Background: I'm a PhD student at Warsaw University of Technology and
> I need to write a project that's going to be fairly intensive in both
> computing and memory usage (symbolic functional decomposition of FSMs
> for FPGA implementation); in particular, the project will implement
> a lot of set operations and graph colouring. I like Ruby a lot, and
> the project has to *work* first, but ultimately it has to be efficient
> in the end. I don't know a lot about C/C++ other than the basic classes
> I took years ago (i.e., I'll have to learn C/C++ from scratch anyway).
>
Are you allowed to use existing open source C/C++ libraries for the
low-level operations, or do you need to implement the whole thing
yourself? I'm sure there are open source libraries, or at least
"academic licensed" libraries that you, being a PhD student, would be
able to use. Unless your advisor wants you to learn how to implement all
this low-level stuff, I'd recommend a hybrid approach -- find some
libraries that do the hard stuff and wrap them in Ruby using SWIG.
> The question: in my case, which approach seems to make most sense?
>
> 1. Pure Ruby. This will most probably not be an option; my gut
> feeling is that pure Ruby will end up being *way* too slow and
> memory-inefficient. Still, definitely the fun approach, and actually
> maybe the fastest prototyping.
>
Do you know Lisp or Scheme? For this type of application, prototyping in
one of them might well be faster than in Ruby. And quite a few Scheme
systems are pretty close to the bare metal / C code, so you'd be able to
do the optimization.
> 2. Ruby with C extensions. Code in Ruby first, then optimise the slow
> parts one after another. This is tempting (mmm, Ruby...), but I'm
> not sure how viable; if I'm going to have to rewrite 90% in C anyway,
> I might as well start with C++ (again, only a gut feeling).
>
This is probably where you'll end up. However, as a general rule,
perhaps 20 percent of the code will need to be in C or C++, not 90
percent. And as I noted above, if you're allowed to use existing C/C++
libraries, you might not have to write anything except SWIG .i
(interface definition) files.
> 3. Pure C++. I have to learn C/C++ anyway almost certainly (for point
> 2 above), so maybe trying to have fun and going with Ruby is not the
> best way this time, and I should simply install CDT, stock on C++
> tutorials and be a brave, if sad, person?
>
It probably won't come to this, but if it does, well, C++ programming is
a very marketable skill once you have your PhD. :)

--
M. Edward (Ed) Borasky, FBG, AB, PTA, PGS, MS, MNLP, NST, ACMC(P)
http://borasky-research.blo...

If God had meant for carrots to be eaten cooked, He would have given rabbits fire.


2 Answers

Shot (Piotr Szotkowski)

1/17/2007 6:45:00 PM

0

Thanks a lot for your reply, Ed!

M. Edward (Ed) Borasky:

> Are you allowed to use existing open source C/C++ libraries for the
> low-level operations, or do you need to implement the whole thing
> yourself?

I'm allowed to use anything I want. My supervisor created a couple
of C++ libraries that he thinks I might reuse (but I don't have to).

> I'd recommend a hybrid approach -- find some libraries
> that do the hard stuff and wrap them in Ruby using SWIG.

Thanks for pointing out SWIG (I'm still a total newbie in the whole
Ruby/OCaml <-> C/C++ interface possibilities, unfortunately; I should
read a lot more on this, but have to make some desions this weekend...).

I'll do all the background reading, of course, but a quick question:
assuming that I have some (objective) C++ classes already, how
easy would it be to use them in Ruby/OCaml? (So far I thought the
C integration was doable, but not necessarily C++, hence my a-bit-blind
shooting-in-the-fog quetions.)

> Do you know Lisp or Scheme?

Neither, unfortunately. Learning Lisp is on my to-do-after-hours list
for a long time already, but it turns out having a full-time IT job next
to the PhD studies means the rare free time I have is best spent away
from the computer, unless I want to lost the rest of my social skills.
;)

I'd love to finally have an excuse to learn Lisp, but I'm affraid I can
only either choose from bringing my Ruby skills up a notch and learning
enough C/C++ to fill in the gaps or commit myself full-time to C++.
(That is, until Benjohn pointed-out OCaml; hmmm...)

> Shot (Piotr Szotkowski) wrote:

>> Ruby with C extensions.

> This is probably where you'll end up. However, as a general rule,
> perhaps 20 percent of the code will need to be in C or C++, not
> 90 percent.

Hmmm, that's tempting. Ruby and me somehow click together nicely, in the
'hey, after two months I still know what I thought writing these!' way
that doesn't seem to happen so much with other languages.

> And as I noted above, if you're allowed to use existing C/C++
> libraries, you might not have to write anything except SWIG .i
> (interface definition) files.

Tempting, again. It seems I'll read up on SWIG a bit this weekend. :)

>> Pure C++

> It probably won't come to this, but if it does, well, C++
> programming is a very marketable skill once you have your PhD. :)

Erm, ye-ah, but... My best job so far is the (current) CiviCRM
web-developement (PHP), and while working with Ruby on Rails instead
would definitely be an improvement, working with C++... well, wouldn't,
to say the least. ;)

(Or maybe I'm just too stupid for the whole mess of header files,
makefiles, compilations, Windows/Linux *almost*-portability and cryptic
runtime errors of everything I ever wrote in C/C++. Or, hopefully,
simply too spoiled by Ruby.)

-- Shot
--
I always thought Smalltalk would beat Java, I just didn't
know it would be called 'Ruby' when it did. -- Kent Beck

Ara.T.Howard

1/17/2007 7:01:00 PM

0