Friday, September 28, 2007

Active record and those darn caps

Due to my recent illness I've had a lot of time to myself in doors. So I've been looking a lot of technologies that have been on my watch list. When looking at ruby's active record I can't help but like and hate it at the same time.

One thing Ruby-lovers pride themselves on is "do as little as possible an get as much for free as possible." Take the following active record example:

class Person < ActiveRecord::Base 
belongs_to :company
end

class Company < ActiveRecord::Base
has_many :people
end

Gavin King, the creator of Hibernate ORM has an interesting comment about this :

At this point, most developers are thinking um, ok, so how the hell am I supposed to know what attributes a Company has by looking at my code? And how can my IDE auto-complete them? Of course, the Rails folks have a quick answer to this question Oh, just fire up your database client and look in the database!. Then, assuming that you know ActiveRecord's automagic capitalization and pluralization rules perfectly, you will be able to guess the names of the attributes of your own Company class, and type them in manually.

Somehow, excitement about the Ruby language has warped their perceptions to such an extent that these people actually believe that this is a good thing!

I completely agree. Ruby plays some magic and when a record is pulled from the database ruby inspects it and adds the needed fields to these "active record" ruby classes. While this is neat and keeps developers from having to plan out their ORM entities I can't help but see the possible problems with doing this on a very complex schema AND entity model.

No comments: