Passenger(mod_rails) released

Filed Under (Rails, Ruby) by Leonardo Borges on 14-04-2008

Tagged Under : ,

Passenger(mod_rails) has been released.

The idea is to ease the pain on rails applications deployment. I tested myself and in less than five minutes I had my application working behind Apache!

I’m not going to say much here besides the fact that it seems like a really good option for rails deployment and people have been talking about it already, including DHH.

But I do recommend a read on the architecture overview document. Be sure to read it all, specially the part on handling concurrent requests.

To install, “it doesn’t get easier than” that.

Good job guys.

Time to reveal

Filed Under (World) by Leonardo Borges on 08-04-2008

Tagged Under :

Some of you may know. Some of you may not. Some of you may find weird. And most of you probably have no idea of what I’m talking about but the thing is: This is a year of big changes for me.

I’ve been hired by Mirai, a Spanish company located in Madrid, to work as a Software Engineer. Yes, it does mean I’ll be moving there. Sooner than later.

Last Friday I’ve received the great news that my work permit has been approved so I can now request my visa in my hometown and move to Madrid, what will probably happen by the end of this month or the beginning of May.

This post probably explain something to some people. And the bottom line is that this whole story means a great step on my career and for those of you that have been following my posts, that’s probably clear.

Because of that I was able to meet wonderful people , learn a bunch of new stuff and be present in important events such as QCon 2008 in London and Euruko 2008 in Prague.

That’s it for now. I’ll keep you posted about my new endeavor.

I’m really excited about this chance and I invite you all for a beer or two either in Rio  or Madrid - Just let me know your preference… :)

JRuby + DB2 + xQuery == bug?

Filed Under (JRuby, Rails, Ruby) by Leonardo Borges on 07-04-2008

Tagged Under : , ,

Update: Follow up link to this issue on JRuby’s Jira, here

As I told in my last post, it was time to give JRuby a serious try. So I took one of our rails projects at work and decided to migrate it to JRuby and see what happens.

We heavily use the XML capabilities of DB2 and this was a huge problem. Every query would work just fine through the activerecord-jdbc-adapter - part of the JRuby Extras . But every Xquery would gracefully fail!

After some debugging I got stuck and decided to get JRuby and activerecord-jdbc-adapter’s source to see what was happening.

As I could see, it has a bug -in my opinion - at the java part of the code. The jdbc-adapter is a bridge to allow Active Record to talk with databases through native JDBC drivers, so it’s normal that we do have a java part here. At this point, what the code does is to inspect the sql statement sent from ruby and decide if it’s a select, update or insert.

I fixed the problem and submitted a patch to rubyforge. I’m not sure if it’s the best solution or not, but now I got the xQueries working just fine.

I’d love to hear from people with similar environments whether this patch works for you or not. I’m sure I didn’t try every possibility.

If you wanna try it, just drop me a message (e-mail in the About page) and I can send the pre-compiled jar file - for activerecord-jdbc-0.8

You can also just check out the code and compile yourself. ;)

QCon 2008: slides available

Filed Under (Conferences, JRuby, Rails, Ruby) by Leonardo Borges on 04-04-2008

Tagged Under : , , ,

Most of last QCon’s presentations are available for download here.

Highlights to Ola Bini’s on JRuby(pdf) and Randy Shoup’s on eBay’s architectural principles(pdf).

And while we’re talking about JRuby, it’s impressive how it’s becoming a recurrent and big subject. Fast. It had its own small space at big event like QCon and in the last Euruko in Prague, we had a presentation by the JRuby Core Developers Charles Nutter and Thomas Enebo.

Big companies are sponsoring JRuby’s development indirectly or directly, like Sun. And other big companies are endorsing its production ready state, like Oracle, which has a publicly available website developed with JRuby On Rails.

It’s past the time to give it a serious try…

Why I like ruby #0 (…or Ruby: The language of the lazy programmer)

Filed Under (Java, Ruby, Why I Like Ruby) by Leonardo Borges on 01-04-2008

Tagged Under : , ,

This is quite funny. A friend, Perl addicted, is now learning Ruby. He really enjoys the language but made a interesting observation: Ruby is a language for lazy programmers!

Well, I have to agree… You know, I love saving keystrokes and achieving more by writing less. And this is so true with Ruby.

Let me give a really simple example, comparing with java - don’t get me wrong… I love java, specially the platform, but it fits well here since I’ve always been a Java guy.

Imagine you have a Phone class with the attributes number and type, which can indicate whether the phone is a land line or a mobile phone. Then you got an array filled with phone classes and you want to narrow it by creating a new array only with mobile phones.

In Java, such a class could look very much like this:

public class Phone {
  private String number;
  private String type;

  public String getNumber() {
    return number;
  }
  public void setNumber(String number) {
    this.number = number;
  }
  public String getType() {
    return type;
  }
  public void setType(String type) {
    this.type = type;
  }
}

Quite simple, isn’t it? But we are telling the compiler many things we actually shouldn’t need to. This class is a java bean and as such, among other things, it needs a pair of getters and setters for each of its attributes.

Now, on with our example, the same class, in ruby, looks like this:

class Phone
  attr_accessor :number, :type
end

Yeah, I know the feeling. This class has exactly what we need: the two attributes with its own pairs of getters and setters each. But we didn’t need to inform it in the verbose way Java has teached us. Cleaner, period.

Now to the code that actually returns the new array containing only mobile numbers. In java, we can do it in two different ways.
Using an ArrayList:

//Create two phone objects, one land line and one mobile
...
// Add them to an array
ArrayList
 phones = new ArrayList
();
phones.add(land);
phones.add(mobile);

//Return an array only with mobile numbers:
private static ArrayList
 selectMobilePhones(ArrayList
 phones) {

  ArrayList<Phone> mobiles = new ArrayList<Phone>();

  for (Phone phone : phones) {
    if (phone.getType().equals("mobile")) {
      mobiles.add(phone);
    }
  }
  return mobiles;
}

Or using ordinary arrays:

// Assume the same phone objects here
...
//Add them to the array
Phone[] phones = new Phone[]{land, mobile};

//Return an array only with mobile numbers:
Phone[] mobiles = new Phone[a.length];

for (int i = 0; i < a.length; i++) {

  if (a[i].getType().equals("mobile")) {
    mobiles[i] = a[i];
  }
}

And you’re good to go. Actually this code with an ArrayList here only looks good thanks to generics. But this is another matter. Let’s take a look at the ruby code that accomplishes de same task:

//Create two phone objects, one land line and one mobile
...
//Add them to an array
phones = [land, mobile]

//Return an array only with mobile numbers:
mobiles = phones.select { |phone|
   phone.type == "mobile"
}

See the difference? Java is a great language but too verbose at times. This is a really simple example but if you take the same principle to a bigger app… yeah, you see where I’m going.

The bottom line… Ruby may be the language of the lazy programmer, as my friend pointed out. But I don’t mind being called lazy as long as I can type less and be more productive. Do you? :)