From: David Balmain Date: 2006-09-22T16:29:16+09:00 Subject: Re: Assistance wanted for integrating existing C-API into Ruby On 9/22/06, M. Edward (Ed) Borasky wrote: > When I wander about the web, I see vast projects, like Sage, for > example, that focus on one scripting language, in this case Python. And > I also see *dozens* of high-quality math packages in either C or C++. > What SWIG gives the developers of these packages is the ability to > expand their market to Perl, Python, Ruby, PHP, Lua, Pike, Tcl, Scheme, > and a few others. > > And it gives the users of the scripting languages the ability to stick > with their favorite scripting language. Again, to use the example of > Sage, it's a very useful and wonderful environment, but I already know > Perl, I'm learning Scheme and Ruby and I don't want to learn Python just > to use Sage! > > So I'm personally a big fan of SWIG, because I think it's a big win for > a lot of people, and because it's a very high quality effort. I think of > it as the "automatic transmission" of scientific and statistical computing. > I'm guilty of doing this myself with Ferret. There is approximately 50,000 lines of very fast search library code there and it's only available in Ruby. I certainly considered using SWIG but there were several reasons I chose not to. Firstly, writing the bindings in C gave me greater control over the ruby API. I guess I could have wrapped the SWIG generated API in another layer of Ruby to get it just right. I'm not sure how much work that would have saved me. Secondly and more importantly, SWIG is great for wrapping C structs in Ruby classes and making the functionality available in Ruby. But going the other way, ie. wrapping Ruby objects for use in the C code is a little more complex. You end up writing a tonne of language specific code in your SWIG bindings anyway so there is still a lot of work for someone to come along and port your code to Python or Perl. Case in point, PyLucene, although implemented with a very well written SWIG wrapper has yet to be ported to another language so it doesn't always work that way. Having said all this, I couldn't agree more with Ed's comments. If you can implement your bindings in SWIG without too many language specific details then you should, even if you can't foresee the code ever being used in another language. Feurio, judging from the fact that you want to wrap your bindings in ActiveRecord, I can't imagine they'd be too complex so SWIG would probably be a very good fit. Cheers, Dave