Archive for the 'ruby-rails' Category

JRuby 1.0 Released!

Charles Nutter: “We have finally released JRuby 1.0, based on the last release candidate, RC3. And what more is there to say? Not really a whole lot…It’s almost entirely RC3, with one or two minor fixes added in. But it’s really turned out to be an outstanding release, and already reports are coming in of folks trying it out en masse. We’re very happy.”

Congrats!

Releases!

Old news, I know, but I just want to underline how some of these releases tie together, possibly to indicate an important trend.

First of all, we have Java SE 6, with Javascript built-in, thanks to Mozilla Rhino.

Then we have JRuby 0.9.2, with a slew of enhancements, bug fixes and performance tweaks.

Finally, after a long wait, Groovy RC-1.

All signs pointing to 2007 as the year of dynamic languages on the Java platform? It really seems likely.

On an unrelated note, I am also pleased to announce the relase of Apache Abdera 0.2.0 (incubating). Nothing revolutionary here, but an impressive number of features already for a 0.2 version. Very stable and surprisingly bug-free also.

RailsConf Podcast

Cool, I have my first podcast online! It’s a recording of the Ruby for Java Programmers talk I did at the recent RailsConf Europe. I usually hate hearing my recorded voice, but I think I came out quite good on this one. I only have to train myself not to say “er” too often: It’s probably not so noticeable when you’re watching a presentation live, but it gets annoying on a recording.

You’ll be able to listen to all the other podcast, as soon as they get uploaded, at Skills Matter. It would be nice to have the slides together with the audio, but the download link gets you just the mp3 file. Luckily for you, I have them here on my website.

Update: mp3 file is here.

My RailsConf slides

rails_logo_remix.gifThis post is to the benefit of the attendees of my RailsConf talk of today. I’ll try to post more about RailsConf when the pace of things slows down a bit. In the meanwhile, you can download “Ruby for Java Programmers” slides here.

Update: Some photos here. 

Re: Outsourcing the performance-intensive functions

While I’m waiting to board my (delayed, once again) flight to London, I am doing some blog surfing and just came upon this quote from DHH:

“The era of islands is over for most development scenarios. You don’t have to make one definitive choice. Instead, you get to hog all the productivity you can for the common cases, then outsource the bottlenecks to existing packages in faster languages or build your own tiny extension when it’s needed.”

Well, the era of islands did never actually begin for pragmatic developers, to be honest, but anyway I think this sentence, and all of David’s piece, could very well be taken as an endorsement of the work I’ve been doing: investigating the integration between the Ruby and Java worlds.

I like is so much that I’ve just added a slide with the above sentence to my presentation for tomorrow.

And no, I don’t even want to touch the “language wars” thread with a pole. Use the right tool for the job and to each his own.

No joy with camping on JRuby

camping.pngWednesday I’m flying to London, where I’ll be speaking at the European Rails conference. I’ll be presenting on the same subject I did at OSCON: Ruby for Java Programmers.

At OSCON I demoed installing and running Rails on JRuby during the second half of the talk, but for EuroRails I’m trying to think of something different, mostly because I don’t want to steal the scene from Charles, who will be demoing exactly that. My backup plan involves demoing an installation of camping, following Ola Bini’s tutorial.

I’m not sure it’s a good idea to talk at a Rails conference about something else than Rails. In any case, I’m not even sure I can make it, since I cannot even get camping to install using either JRuby 0.9.0 or the latest code from svn:

Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR:  While executing gem ... (NoMethodError)
    undefined method `rubygems_version' for 0.9.7:Gem::Version

I’ve opened a new issue about this, but I doubt it’ll get fixed by tomorrow. So I probably need to find a backup plan to my backup plan.

Slides of my OSCON talk

This post is just to provide a pointer to my slides: they are here if you’d like to have a look at them. I’m not going to write anything more about the OSCON today: my head is exploding with all the things I listened to. Plus I need to decompress after the tension that always goes with speaking in front of an audience, especially in a tongue that is not your own. I’m just looking forward to the exhibit hall reception that is going to kick off at 6. Hope they have lots of beer.

Technorati Tags: , .

Speaking at ApacheCon about Atom

After going to Portland next week to speak at OSCON, it looks like I’ll be crossing the ocean once more in October to speak at ApacheCon US 2006, where my proposals for two talks titled:

  • Ruby for Java Programmers, and
  • Atomized: How to consume and publish Atom using Open-Source Java tools

were accepted. Many thanks to the ApacheCon organizers for giving me this wonderful opportunity!

I’m curious to know who else will be speaking. The only other one I know of at this time is Andrew.

The talk about Atom reflects my recent interest in the format, the publishing protocol and its applications. I can’t say much about that since most of what I’ve been doing around it is covered by NDA, but Atom rocks. Looks like Tim Bray shares the same feeling, to the point of being horrified to see nothing about the Atom Publishing Protocol on the OSCON schedule. Luckily he has enough clout to convince Nat to include him in the program. That’s one talk I’m not going to miss!

Using the Ruby Bindings for Subversion

Today I set out to develop a simple proof of concept: a Wiki developed in Ruby on Rails using Subversion as a repository.

Doing a very basic Wiki using RoR is a piece of cake, given the availability of RedCloth and BlueCloth. However, having it use Subversion instead of a relational database is something that needs more work.

Luckily, the latest Subversion release (1.3.2 at the time of this writing) includes full Ruby bindings using SWIG. Unluckily, the precompiled package for OS X that I was using (from the fine folks at Metissian) doesn’t come with the bindings, so I had to reinstall Subversion from the source: nothing really complicated here, but the options for getting it to work over HTTPS should be documented better.

Speaking of documentation, there is apparently none for the SVN Ruby bindings… which is a shame. I could only find something regarding installation thanks to PJ Hyett, why the lucky stiff and Garrett Rooney, but armed with the source, using BountySource’s bsSvnBrowser as a sample (read-only code though, while I need to read and write) and especially Garrett’s book Practical Subversion1, I managed to conjure up some code that, on the surface of it, seems to work.

Here’s a snippet that saves an ActiveRecord instance to the SVN repository:

  def save(validate = true)
    return false if (validate && ! valid?)
    repo = Svn::Repos.open(REPO_PATH)
    repo.fs.transaction { | txn |
      txn.root.make_file(title)
      stream = txn.root.apply_text(title)
      stream.write(text)
      stream.close
    }
    return true
  end

I’m not sure this the correct way to implement save, but it works.

1. When I reviewed Garrett’s book, I wrote: “It’s written largely from the perspective of a repository administrator or a power user wanting to extend the system and develop new applications on top of it, as the long (73 pages) chapter on Subversion APIs demonstrates.” Finally that long chapter has been useful to me!

Rails 1.1.4 Does Run Unmodified in JRuby

Yes, I was dumb. The second step should have been:

jruby bin/rails myapp

With that in mind, Rails is able to generate an application and run Webrick, without any apparent glitches, apart from a warning from the Oracle adapter, as is demonstrated by the screenshot below:

JRuby-Rails.png

Moreover, in order to avoid waiting a lot of time while it is processing docs, it is advisable to install Rails as:

gem install rails --include-dependencies --no-rdoc --no-ri

Technorati Tags: , , .

RailsConf 2006 Keynote Videos

If you, like me, couldn’t attend the RailsConf 2006 in Chicago last month, you’ll perhaps be glad to know that ScribeMedia is putting online the videos of all the keynote speeches. Martin Fowler’s and Dave Thomas’ videos are already online and the other ones will follow shortly.

Also, keep in mind that registration for RailsConf Europe is open, so if you couldn’t make it to Chicago because of distance, you have another opportunity to hear some of the same presenters, like Dave Thomas and DHH himself, plus Kathy Sierra, Chad Fowler et. al.

Rails 1.1.4 Should Run Unmodified in JRuby

Charles Nutter: “Now, with the release of 1.1.4, the following will all work out-of-the-box with JRuby 0.9.0 (currently in RC status):”

gem install rails --include-dependencies

Check

# and use --no-rdoc for now...it's too slow

Check, even though it insisted on building documentation and yes, it was slow, but it finished eventually.

rails ~/myapp
lib/ruby/gems/1.8/gems/rails-1.1.4/bin/../lib/rails_generator/options.rb:33:
        in `method_missing': undefined method `write_inheritable_attribute' for
Rails::Generator::Base:Class (NoMethodError)
        from lib/ruby/gems/1.8/gems/rails-1.1.4/bin/../lib/rails_generator/options.rb:33:
        in `default_options'

OK, we’re almost there, but not quite there yet:

Keep in mind that we don’t officially “support” Rails just yet; there’s more work to do. We are, however, another leap beyond the JavaOne demo, and at this rate things are looking very good for an end-of-Summer JRuby 1.0.

I’m not sweating over it. Take your time and make it really rock, folks.

Ruby for Java Programmers, Part VI

In the previous episode from this series, I showed you how to use XML-RPC to call Java code from Ruby over the network. In this article, we will do the same, but using SOAP instead of XML-RPC. One advantage of SOAP over XML-RPC is the fact that SOAP endpoints can be described using WSDL and, by using Ruby’s extensibility, new methods can be created on the fly to mirror the methods declared in the WSDL, therefore giving us a lot of nice loose coupling.

Moreover, toolkits exist to automatically create WSDL descriptions from Java classes, so you won’t have to do it by hand. One of these toolkits, and the one we’ll be using in the examples here, is XFire. The most recent version of XFire available at the time I’m writing this is 1.1-RC1. I suspect this example will work just as well when 1.1 final is released. You’ll also need Java5 and Maven 2.

Maven is handy for automatically downloading all the necessary dependencies and running the demo inside a servlet container, using the Jetty6 plugin, without writing much code or configuration. Of course, you can always download all the necessary JARs by hand and drop them, together with the demo code, into the servlet container of your liking.

You can follow XFire’s Quick Start tutorial to set up a simple SOAP service, or you can simply grab a copy of this archive, which adds some more data to the tutorial sample, unzip it and run mvn jetty6:run from its root directory, once you have Maven installed. Go grab a cup of coffee while Maven downloads all the dependencies. Finally test that everything is OK by requesting a copy of the WSDL file from http://localhost:8080/services/BookService?wsdl.

On Ruby’s side, all that is needed is already provided by Ruby’s own core soap library, in particular SOAP::WSDLDriverFactory.

Here’s how you’d call your service from Ruby:

require 'soap/wsdlDriver'
WSDL_URL = 'http://localhost:8080/services/BookService?wsdl'
driver = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
books = driver.getBooks(nil)
p books.out.book[0].title
book = driver.findBook(:isbn => '222')
p book.out.title

A couple of minor nits:

  1. The BookService#getBooks method in Java takes no arguments, but if you try to call driver.getBooks without arguments, Ruby complains about a missing argument. Apparently, passing a ‘nil’ value fixes it, but I’d like to know why this is so.
  2. XFire add this extra ‘out’ element to its generated schema. This is mildly annoying as you always have to use it in order to access the real values you are interested in.

On the pro side, you can set up all of this with very little configuration. The only configuration that is going to change from one application to another is XFire’s services.xml file which maps service names to service classes, and even this is pretty straightforward:

<beans xmlns="http://xfire.codehaus.org/config/1.0">
  <service>
    <name>BookService</name>
    <namespace>http://sourcesense.com/BookService</namespace>
    <serviceClass>com.sourcesense.xfire.demo.BookService</serviceClass>
  </service>
</beans>

Technorati Tags: , , , , .

Duke Nukem Forever is a Rails application

nukem.jpgThe long wait is finally over. After having been in development since 1997, we finally have a demo version of Duke Nukem Forever. Not being much of a gamer, I’m not that excited, but being a web developer I finally feel vindicated: According to Ars Technica, Duke Nukem Forever is a Ruby on Rails application, runs in a browser and uses Ajax:

From the ReadMe.txt file, I also found out why we’ve been waiting so long for Duke Nukem Forever. Wanting Duke Nukem Forever to run on all platforms, but not wanting to bust a nut writing three different versions (not to mention having to come up with both PowerPC and x86 binaries for Mac OS X), the developers came up with a clever solution. Duke Nukem Forever has been rewritten as an Ajax application written using the Ruby on Rails framework. What it means is that Duke Nukem Forever has skipped a generation and is the first true Web 3.0 application, and it runs entirely in your web browser. Any web browser, on any platform… well almost.

This clearly demonstrates that the Web is the platform for everything, including high-end, 3D games with plenty of sex and gore. Go Rails!


Does Rails want to be enterprisey?

The now infamous post by James McGovern on Ruby’s lack of “enterprise” qualities sparked an interesting thread on the Rails mailing list.

The thread is interesting because it is strangely devoid of flames and name-calling and, apart from the usual FUD about Java being slow being spread by a few clueless people, quite informative. I particularly appreciated the posts by David Johnson.

One thing seems clear to me. In order to become more successful in the enterprise, Ruby needs to overcome some of its current limits, like the lack of serious internationalization and threading features and of a serious threading implementation.

It also seems clear that, contrary to what McGovern writes, Ruby is not a train wreck waiting to happen. If it’s currently lacking in some aspects, there’s no reason not to expect that it will get there, given enough time.

Some people however wondered whether it’s really a good thing for Ruby and Rails to become more “enterprisey” or rather if it would lose its simplicity and appeal by trying to go beyond simple database-backed web applications. To me this looks too limiting. My current approach, as I wrote before, is to try to make the Ruby and Java worlds go hand-in-hand together in harmony. Having Ruby running on the JVM thanks to JRuby might do much towards this, particularly if the objective of having Rails running on JRuby is as close as they say it is.

Technorati Tags: , , .

Speaking at OSCON

OSCON.gifJust got this in the mail:

Congratulations! You have been accepted as a presenter for the O’Reilly Open Source Convention 2006 at the Oregon Convention Center July 24, 2006 – July 28, 2006.

The following has been accepted as a 45 minute session for the event:

“Ruby for Java Programmers”

I can’t even try do describe how excited I am. OSCON is the Open Source conference to attend if you’re into OSS — not to mention speaking at it — even if someone may consider it a bit too commercial. At the same time, I’m somewhat scared. I’ll have to prepare a kick-ass talk and double-check all my facts if I don’t want to be thoroughly grilled.

Technorati Tags: , , , .

Italy on Rails

italyonrails.gifVia the Ruby on Rails mailing list I just discovered that there’s going to be a Rails conference in Italy: “Open Source Path is proud to announce the first ever Ruby on Rails conference within Europe to be held in Rome, Italy in the Fall of 2006.”

How cool! I will probably miss the RailsConf in Chicago, but this one being so nearby, I’m not going to miss it!

By the way, where’s the Italian Rails community? I know there’s an Italian Ruby users group, but I don’t know of any Rails-specific Italian user group, community or whatever. If you know of some, or would like to organize one, please leave a comment here.

Book review: Programming Ruby

0974514055.01._AA_SCMZZZZZZZ_.jpgProgramming Ruby, by Dave Thomas.

I finally decided to review this book, having read it quite some time ago. The reason I waited this long is that I feared I wouldn’t have been able to provide a fair assessment of the merits of this book. My problem is that, nowadays, I get easily bored reading yet another programming book. And a book entirely dedicated to a single programming language was bound to bore me infinitely.

That’s what happened, actually. I got so bored that it took me a really long time to finish it, even after skipping entire chapters. I managed to finish it only because I forced myself to do it.

I know Ruby is cute, and has lots of nice and innovative features, but I just can’t stand anymore reading operator precedence tables, variations on the basic control structures and core libraries. Last time I got excited by a programming language was with Java, and that was circa 1995. I’m too old for that.

But I must try to stay objective and think how useful “Programming Ruby” could be to a young programmer and I have to admit the answer would be: a lot! As is customary with titles from The Pragmatic Programmers, quality is very high, both from a content point of view and from a presentation one as well. Well written, it even manages to inject a bit of humor into a dry subject. If you want a one stop shop reference for all Ruby, that’s it! Not much more to say, except that I’d have liked, at times, the code samples to be longer, more structured and less contrived, but it’s a minor nit.

I suggest that you read it in bits and pieces, not cover-to-cover and if boredom gets you, you can always get a little of why’s (poignant) guide to Ruby as an antidote.

(0)

Ruby for Java Programmers, Part V

If you’ve been following the previous articles in this series (Part I, Part II, Part III and Part IV) but are not yet satisfied with the range of solutions I presented for calling Ruby code from Java, here’s another one for you.

This one involves running your Java code as a separate process and interacting with it using some form of Web service (XML-RPC, SOAP or a RESTful service). We’ll use XML-RPC for this sample, mainly because it’s very easy to set up and use. You’ll need Apache XML-RPC version 2 to make the code run. Here’s the java code:

public class RPCFetcher {
    public static void main(String args[]) throws Exception {
        WebServer server = new WebServer(8080);
        server.addHandler("$default", new RPCFetcher());
        server.start();
    }

    public Vector fetch(String url) throws Exception {
        URL feedUrl = new URL(url);
        FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
        FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache);
        SyndFeed feed = fetcher.retrieveFeed(feedUrl);
        Vector items = new Vector();
        for (Iterator it = feed.getEntries().iterator() ; it.hasNext() ; ) {
            SyndEntry entry = (SyndEntry) it.next();
            Hashtable map = new Hashtable();
            map.put("link", entry.getLink());
            map.put("title", entry.getTitle());
            map.put("publishedDate", entry.getPublishedDate());
            items.add(map);
        }
        return items;
    }
}

Compared to the previous samples, there’s not much else you need to do, besides creating an instance of WebServer to handle incoming HTTP requests and dispatch them to the appropriate method. However, you need to convert your Java types to something that XML-RPC is able to understand, i.e. strings, numbers, dates, Vectors, Hashtables and little else.

The Ruby client code is much simpler:

require 'xmlrpc/client'
server = XMLRPC::Client.new 'localhost', '/', 8080
entries = server.call('fetch', 'http://agylen.com/feed')
entries.each do | entry |
  p "#{entry['publishedDate'].to_time} #{entry['title']}"
end

Possible drawbacks of this technique are the necessity of having a separate process running and the overhead of HTTP communication and XML-RPC protocol encoding and decoding.

Thanks to Nick Stuart and Erik Hatcher for laying down the basics.

ApacheCon EU 2006 – Dublin, Ireland, June 26-30

Bertrand Delacretaz: “The ApacheCon Planners are pleased to announce that ApacheCon Europe 2006 will be held in Dublin, Ireland, at the Burlington Hotel, June 26-30.”

Hmmm, back to back with the RailsConf, which will be held in Chicago from the 22 to the 25 of June. I wonder if there are direct flights from Chicago to Dublin.