Entity bean bloat

I’m currently getting acquainted with JBoss, SpringSource Application Platform, JBoss Seam and Spring Framework.

One thing that amazes me is the amount of code required for some simple O/R mapping, or I am missing something? I hope to be wrong about this, but it seems like an EJB3 "entity bean" requires, for each column in a database, the following items written and maintained:

  • a private member variable
  • a getter method
  • a setter method

As I have some Ruby on Rails experience, where inheriting from ActiveRecord gives you those things out-of-the-box, I am amazed of the sheer amount of boilerplate code needed in Java for the same thing! I asked a friend wih ZendFramework knowledge about how it worked there, and it seems like Zend_Db_Table_Abstract works just like ActiveRecord.

I can’t be the first one perplexed by this, especially not when the development guide for the ASM 3.0 Java bytecode engineering library contains exactly the above parts as an example of generating bytecode! (See section 3.1.3.)

Making a demo login with restful_authentication

In order for someone to give The Project (Min Packning) a try it was required to register an account and provide a valid e-mail address. This is an obstacle, so I wanted to add a way for people to try the service without registering. It was actually very easy. I created a demo user account, added a demo method to SessionsController and added suitable routing. Now visiting www.minpackning.se/demo will give a logged in session as the demo user.

In app/controllers/sessions_controller.rb:

  def demo
    params[:login] = 'demologin'
    params[:password] = 'demopassword'
    create
  end

In config/routes.rb:

  map.demo '/demo', :controller => 'sessions', :action => 'demo'

The ThoughtWorks Anthology

According to the latest mail I got from The Pragmatic Bookshelf, one of their upcoming titles is The ThoughtWorks Anthology, but I couldn’t find anything about it on the web. Out of pure curiosity I’ve sent an inquisitive mail to see if I can find out more about it. Maybe it’s related to the No Fluff Just Stuff books?

Another upcoming book is Facebook Platform Development with Rails, which sounds nice but I’ll probably never get around to do it… 🙂

Update Andy Hunt kindly replied to me:

It’s a collection of essays from leading ThoughtWorkers. We’ll have an announcement up in the next week or so.

Sounds interesting!

My first AJAX!

Probably years after everyone else, I’ve made my first AJAX-enabled web page today. As I do this from within Ruby on Rails, it was virtually painless to remove or replace a piece of HTML.

My next AJAX step was to get in_place_editing working. The first problem was the InvalidAuthenticityToken and the second issue was that I use a different controller, but now it works fine!

Printing “Things” in The Project

The Project will allow users to create and edit something I call “Things” in this article. One feature that is quite high on the priority list is to be able to print Things. I found the article “Print this page” with Ruby on Rails but I wanted a separate page for printing a Thing. I have created a layout called “print” and my ThingsController contains a method like this:

  def print
    @thing = current_user.things.find(params[:id])
    render :layout => "print"
  end

My routes.rb contains something like:

  map.print_thing '/things/:id/print',
    :controller => 'things', :action => 'print'

The print layout is currently bare-bone HTML with this script snippet right before </body>:

<script type="text/javascript">javascript:print()</script>

Rant about Ruby on Rails

Zed Shaw rants quite a bit, stating that Rails Is A Ghetto. Most things I read about RoR are good things, and I guess that some of it is written by the people that Zed grumbles at. It is quite refreshing to hear other opinions, even if they might not be what I want to hear.

The humble beginnings of The Project

Yesterday and today I took some time to work on The Project. (Tomorrow I’m back at work, so much for a holiday project.) I tossed aside requirements on a strictly Swedish interface, so the controller names are in English and I don’t use Ola Bini‘s Swedish Rails yet. Honestly I haven’t done any TDD/BDD yet either. The excuse I tell myself that I only cannot learn everything at the same time.

I lookup things in the Rails 1.2 book but as I’m using Rails 2 I’m browsing the web quite a bit too. One very useful resource I’ve found so far is Akita’s tutorial. So far I have restful_authentication working (from the restful_authentication gem), a “welcome” controller and two domain-specific models. I’m working on two related controllers.

A few words about using an activation step when registering a new user. I started out with the Restful_authentication & Activation instructions but I thought that having a HOST global variable was really silly so I found the retardase_inhibitor plugin and now I can properly generate URLs in the ActionMailer.

I want to read “Peopleware” again

Bruce Eckel recommends Peopleware — Productive Projects and Teams (by Tom DeMarco and Timothy Lister) in his recent weblog entry The Mythical 5%. When I ordered a bunch of book recently I was thinking of including both The Mythical Man-Month by Frederick Brooks and Peopleware, but I didn’t. It is probably a good idea to read both of them again as I haven’t read them for five years or so and I’m trying to be one of those 5% mentioned by Bruce Eckel…

I have plenty to read anyway though, and yesterday I spent some time on my latest project. I want to use Rails 2.0 but I keep Googling and reading pages like Rails 2 Upgrade Notes a lot when things don’t work exactly as they did in previous versions. A complicating issue is that the web interface for my project will be in Swedish so I will give my controllers Swedish names, but I want English names in the database so it will either be a kind of mix under the hood or I’ll use set_table_name in the models. I hope that Swedish Rails can help me out a bit!