January 02, 2006

Ruby on Rails

I have a particular personal project, which I've told just a few people about. It is very experimental, and basically has to do with creating a new type of online discussion, that fixes a number of problems I've noticed with discussion boards, usenet, and blog discussions.

I've decided to do this in Ruby on Rails, which is a web application framework that has become very popular lately. This is actually my second attempt at this. My first was fairly successful technically, but proved that some of my ideas about my project were invalid. I believe I've fixed the conceptual problems, so I'm redoing the project.

Ruby on Rails is so well liked because it makes everything simple. Whereas in previous web frameworks, only 10% of your effort went to critical code, the rest going to supporting code. With Ruby on Rails, there is pretty much only critical code. However, I find that still only 10% of my effort if going to writing critical code, with the rest of my time going to understanding the framework, due to strange problems I have.

I believe I have some fundamental misunderstandings about how Ruby on Rails does things. For instance, I was surprised to learn that you can have multiple different objects that represent the same thing! The following code returns false.


a = Foo.find(id)
b = Foo.find(id)
a.equal? b

In this example, we load two objects by the same id, and compare to see if they are the same object. They are not.

This amazes me. If you are in a transaction, and change the state of an object, the same object referred to through some other path will not reflect that change. This could cause endless confusion, but I suppose there is some way you have to program so that this problem would never reveal itself.

A similar problem is one where a change to one object causes a change to another object. So if every call to an instance method of a database object (model instance, in Rails parlance), Foo.doSomething causes some data in a linked object of type Bar to change, then how do I write the code so that this happens? If I change the instance of Bar on Foo.doSomething, then I have to keep that instance as an instance variable on Foo, until I save. Alternatively, I could override the save method, and make the change there, if necessary. However, in either case I have to override save so that the depended instance of Bar is saved as well. This doesn't work, throwing an error about the number of arguments to save.

Also, why do I have to save? And why do I have to specify transactions manually? Why can't everything in one web request be a single transaction, and all modified objects automatically saved?

I guess I really haven't "gotten" Rails yet. Although perhaps there is nothing to get, and it really is only suitable for the most simplistic applications.

Posted by ahyatt at January 2, 2006 05:06 PM
Comments
Post a comment














To post a comment, please type in the number of hours in a day (this is to help protect this site from spam by ensuring you are a human):