Monday 29 August 2011

First impressions of Rails (and first entry)

I've been a Java developer for the last 8+ years. I worked with some other languages: C++, Fortran (yes... I know... ), javaScript. But most of my work was done in Java.

I recently decided that I want to try Ruby. I have a new project in mind, and everybody talks about how fast developing with Rails/Grails is, so I wanted to give it a chance.

What do you do when you change from one language to another? get a reference book? Well...not what I did :D It happens that my brother has been working with Rails for more than a year so instead of getting a book I'm trying to do it the hard way: reading blogs and asking my bro. whenever I find something weird.

OK so time to say what I think of Rails right now. Remember, just 1 day working with it (4/5hours actually):

I REALLY like Cucumber. It's great that you can specify your test in a human readable way, I don't have a Functional Analyst in my project, but I think you could use cucumber to let nontechnical people to write some test cases for you. Someone told me today that there are frameworks in java for doing the same thing: JBehave (Looks like I haven't done any full app in a while :D ). Anyway, important thing to notice: these are integration tests, you still need to create your unit tests.

I like how Rails organizes your app, it basically forces you to use good programming practices(thumbs up). Scripts are great you can generate your model classes, the db schema and all simple forms for your CRUD operations

What I DON'T Like is that you have to think in terms of the db first. I like to think in terms of objects, I don't want to pay attention to the DB schema when I'm writing my model.

Here's an example: Suppose you want to create a class SpecialUser with some attributes... let's say: name and twitterId.

rails g scaffold SpecialUser name:string twitterId:string

this works great, in order to make it work you run
rake db:migrate

and you are ready to go.

Now let's say we have a class User with the attribute name and we want this to be a subclass, so if you read the doc you'll find that you can specify the parent class with --parent so you run the script:

rails g scaffold SpecialUser twitterId:string --parent=User

You go an check the code and find

class SpecialUser < User
end

So you're like: "mmmmmmm this is weird... where's my twitterId attribute?" moreover, you check db/migration and there's no script for this new class... but if you do a grep by twitterId you'll find that the html pages were created.

So: looks like IF you want to have inheritance Rails will do PART of the job but you will have to write the db and model by yourself. I'm wondering how hard would have been to make it out of the box.

Next step: find out if there's a simple way to do inheritance or I have to write the whole thing by myself.

No comments:

Post a Comment