A new Ruby/Objective-C bridge

Posted by Damien Pollet Fri, 05 Jan 2007 17:51:40 GMT

Tim Burks recently announced RubyObjC, a new binding between the Ruby and Objective-C programming languages. Tim previously documented the other Ruby/Objective-C binding, RubyCocoa, through the rubycocoa.com website.

To get started with RubyObjC:

  1. install the gem: sudo gem install rubyobjc --source http://www.rubyobjc.com
  2. generate an application: rubyapp myapp
  3. build it: cd myapp; rake
  4. run it: rake run

Then follow the tutorial.

On the implementation side, the docs mention that RubyObjC directly inserts handlers for Ruby methods in Objective-C method tables and adds handlers for Objective-C methods to the Ruby method tables, so the bridging overhead should be minimal.

I would really like to have such a bridge for Squeak

Update: RubyCocoa 0.10.0 was just released too (via lrz).

Posted in  | Tags ,  | 4 comments

Bad assumptions

Posted by Damien Pollet Wed, 13 Dec 2006 02:15:54 GMT

James Robertson already nicely answered this guy about Cees’ comments on Java, so I…must…not…troll…further…phew.

But I couldn’t ignore this:

6 months isn’t really enough to get properly comfortable with all aspects of a language.

OK, so let’s make my timeline of things with Smalltalk:

  • getting over the, hmm, aesthetics of Squeak… not sure I’m done with that :-)
  • learning the whole syntax, 30min.
  • starting to get my way using the tools and write simple stuff, 1 day.
  • knowing the basic stuff in the library, like iterations, conditionals, understanding that the debugger is really my best friend: 1 week
  • getting used to the image, exploring the system, reading the source, and starting to get what object-orientation really was about: 1-2 months. At this point, reading code really becomes an opportunity to learn interesting new stuff from others.

It’s been a little bit more than six months now and think I can say I’m properly comfortable with all aspects of the language. In fact I’ve also looked into all this machinery that looked like a mysterious black monolith before: the metaclass hierarchy, what exactly is a virtual machine doing, how are exceptions and continuations implemented, at the runtime objects like CompiledMethod, the bytecodes, etc.

Even with Python or Ruby I wasn’t drawn in the language like with Smalltalk. Both have really weird design decisions, like meaningful spaces, and the general procedural-with-OO-afterthought feeling for Python, or the inheritance and interpreter kludges in Ruby. Smalltalk and in particular Squeak does have ugly code (Morphic anyone?), but it’s just library code. The language itself has a beautiful ideal and it’s so light and fast while being so dynamic, you just have to go and look how that miracle happens.

Posted in  | Tags , , ,  | no comments

Diff hack for DarwinPorts conventions

Posted by Damien Pollet Sun, 18 Sep 2005 00:49:00 GMT

I’ve put together a small script to help creating the patches when packaging software for DarwinPorts. Nothing really clever but it’s all in shiny red Ruby code, so I thought it would be pretty on my green blog :-)

DarwinPorts’ packaging conventions for the patch phase are to make one patch named patch-<filename>.diff for each modified file in the upstream sources. Also, those patches will be applied with patch -p0, so either you have to call diff from the modified sources tree, or you have to go in each patch file and tweak stuff and it’s really tedious and I’m too lazy to do that by hand repeatedly.

Read more…

Posted in  | Tags , , ,  | no comments

Attempts at Typo caching

Posted by Damien Pollet Sun, 12 Jun 2005 12:41:00 GMT

Yesterday I tried to get typo to generate static versions of the main pages to improve the speed. I’m running it on a Sun workstation I got for 10 euros, so ruby is not exactly zippy :-)

The first problem is with pagination: the page number is passed as a parameter in the URL, so I added the following route:

map.connect 'articles/page/:page', :controller => 'articles',
  :action => 'index', :page => /\d+/

With this route, page 2 gets cached in public/articles/page/2.html for instance. Which is a problem since the links don’t include the .html extension. Second problem is the main page, which gets cached as public/index.html but since it’s accessed by the root URL, rails serves it even when the cache is here. I tried to tweak how apache rewrites the URL, without success:

RewriteRule ^/$ /index.html [R=301]

# or, later:
RewriteCond index.html -f
RewriteRule ^/$ /index.html [L]

Next problem will be to update the aggregated feeds in the side bar, even when rails is completely bypassed by the cached page ; a good place to add some ajax goodness, but I guess I have to RTFM a little more about routes and mod_rewrite before that :-)

Update

It seems I got the routes to work… the rewriting rules are now:

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]

… which happens to be the default. duh.

I’ll have to fix the “posted by whom that many days ago” subtitle, and check that cached pages are correctly invalidated. There is still the RTFM’ing part to do, because there’s some rails routing magic I don’t really understand yet.

Update 2

Had some problems with cache sweeping but it works now; it’s probably a little zealous, but it’s here. It’s still broken for the pagination links at the bottom, though… I have to find how to cleanly recompute the page number to sweep, or how to sweep all pages at once (e.g. find how much pages there are in total).

Update 3

The javascript trick to display post dates works now, so I sent my changes.

Posted in ,  | Tags , , ,  | 5 comments

Ruby traits... nearly

Posted by Damien Pollet Tue, 03 May 2005 23:38:00 GMT

Traits -- the ones à la Stéphane Ducasse -- are mixins done the right way. Basically, it's clear what features the trait relies on, and the including entity has control over what gets included or not : features can be dropped or renamed, Eiffel-style.

Traits rock.

So I wanted to (try to) implement traits in ruby, partly for fun, partly because it would be a pretext to submit to the Dynamic Languages Symposium.

And then I just saw ruby traits in the RAA feed and nearly fell from my seat. It certainly needs a more awake look, but in fact it seems it's just an enhanced version of the attr_* macros. phew.

Posted in  | Tags , ,  | no comments