No Rails for me

February 3rd, 2008

Source: FlickrI believe there is a lot of Slick in Ruby on Rails. People that are smarter than me like it so there must be. So I finally looked at doing a project in it, but decided I won’t use it after all. I like library approach more than framework one. That is the core problem why I kept away from all the Rails-like systems for so long.

So what don’t I like? I don’t want to learn or use some framework specific abstractions for things that stand on their own. I want to see XHTML as XHTML, client side JS as JS and work with DB via SQL or in a SQL like manner. Second… I looked at example code and it was nice but I like how I code right now more.

//RoR example from onlamp.com
def update
@recipe = Recipe.find(params[:id])
@recipe.date = Time.now
if @recipe.update_attributes(params[:recipe])
flash[:notice] = 'Recipe was updated.'
redirect_to :action => 'show', :id => @recipe
else
render :action => 'edit'
end
end

//this is how I do something like it in php
function update($d)
{
if ($this->db->update(array(
'set' => array_merge($d, array('date' => '#noQuote#NOW()')),
'where' => "id = {$d['id']}"
)))
$this->addMsg('Recipe was updated.');
}

I like Ruby’s syntax 10x more than PHP’s and Ruby is much more advanced (in ways that I care) as a language. But there are several problems why I personally don’t want to code as it is coded above.

  • Why do I have to find the record, change it and store it back? Databases have UPDATE right?
  • Why use a external language’s API method for creating current date to store in a DB (and think about formats and all sorts of stuff) if DBs have NOW() and other functions for this?
  • Can one action create only one flash notice?
  • Why does a method that makes modification to the database (a backend method) handle where user will get redirected after the action??? This is total crap, this method should only update the DB and not have any effect on the frontend, so it can be called from anywhere you need it (admin panel, some ajax call, RPC, frontend..) … I didn’t even bother digging into MVC because I found it too extreme and impractical from what I saw on the surface and my code never does that.
  • How can it be that DSL-s (domain specific languages) are oh-so-cool and at the same time ORM’s, Active Records and similar stuff that puts wrappers around them is also oh-so-cool?
  • Isn’t Active Record so MS Access 98?

I am not saying RoR is crap. First, there were hundreds of MVC+templates+ORM+… frameworks out-there before RoR and RoR obviously did many things better because now there are thousands of (RoR-ishy) frameworks there. People do report massive productivity boosts in using it. And productivity is the whole point of improving various development routines and methodologies. So, live and let live…

(edit: zemantified also)

Read and let read :)
  • del.icio.us
  • Reddit
  • Digg
  • DZone
  • email
  • Facebook
  • HackerNews
  • Twitter
  • StumbleUpon

4 Responses to “No Rails for me”

  1. Srđan Prodanović Says:

    Why do I have to find the record, change it and store it back? Databases have UPDATE right?
    The power of ActiveRecord is not just in the object-relational mapping, but in it’s behaviour as a Model. The most powerful relation mapping and validation goes on dynamically in a Ruby object, and that object needs data for it’s initializers and properties. Since you deal with data validation and errors in the model, you never deal with a MySQL error, but an ActiveRecord error, which abstracts the error handling logic to become more loosely coupled to the database server. But in case you have no validations or relations to take care of, you can always do a simple Recipe.update params[:recipe]. If you really feel like writing vanilla SQL by hand though, you can still do Recipe.connection.execute "UPDATE recipes SET body = '" + params[:recipe][:body] + "' WHERE id = " + params[:recipe][:id]. Notice you have no input validation and way more keystrokes the more you try to complicate.
    Why use a external language’s API method for creating current date to store in a DB (and think about formats and all sorts of stuff) if DBs have NOW() and other functions for this?
    Occasionally you may want to take in account timezones. The example you pasted is pre 1.0 though, timestamps are managed automatically for a long while now.
    Can one action create only one flash notice?
    You can modify the variable flash[:notice] and store whatever you like. You’ll rarely need a notice to last longer than one action, or a several notices per one action. If you ever do, it’s good to consider the design again, and check if you can break an action down to more basic functionality, but you can always use http://software.pmade.com/stickies if necessary.
    Why does a method that makes modification to the database (a backend method) handle where user will get redirected after the action??? This is total crap, this method should only update the DB and not have any effect on the frontend, so it can be called from anywhere you need it (admin panel, some ajax call, RPC, frontend..) … I didn’t even bother digging into MVC because I found it too extreme and impractical from what I saw on the surface and my code never does that.
    You seem to have missed the concept of MVC. The method that updates the database can be added to the model, so you call it in a nice abstract way. And controller is the only place you should make database requests from (or at least that’s what you should try to stick with). For instance, you can have a complex transaction defined in your model, and call it from the controller with a one liner like Store.find_near params[:location], where the location parameter can hold streets and cities your geotagged Store model will use to order results by distance.
    How can it be that DSL-s (domain specific languages) are oh-so-cool and at the same time ORM’s, Active Records and similar stuff that puts wrappers around them is also oh-so-cool?
    Because simplifying something in a pattern and adding a layer of abstraction is the way software develops to become more powerful than the sum of it’s pieces.
    Isn’t Active Record so MS Access 98?
    Hah, as much as Ruby is Microsoft QBasic.
    Nobody can force you into anything, but expect praise and encouraging from Ruby enthusiasts like me :-) You have to aggree that when you get to write this much to have a working comments controller, you can make a lot of comment-enabled web apps for sure :-D

    class CommentsController
    If you feel like getting together with Ruby on Rails developers from Slovenia, join us at http://ruby.meetup.com/126/

  2. Srđan Prodanović Says:

    A piece of code there got filtered because I forgot to escape <


    class CommentsController < ResourceController::Base
    belongs_to :commentable
    actions :new, :create
    create.wants.html { redirect_to parent_object }
    create.wants.js
    end

  3. janko Says:

    Hi, Srđan… Thanks for your explanation a LOT. I never say never and know that I don’t know everything so didn’t close any doors to ruby.

    I would like to ask so for some details or object at some of the points you made but I will rather take a little lime and larn some more about few topics of programmign that I don’t yet know that well.

    Otherwise I see many interesting things going on with Ruby itself (concurency paradigms for one) so I will surelly be checking the sole ruby again. I was a python programmer for a long time (a while back) and I always considered ruby an python somewhat similar so I didn’t yet bother to pick up ruby. But with RoR and all the fuzz ruby is now progressing into interesting directions so I keep an eye on it .. we will see what will come out..

    thanks,
    j.

    hm.. meetups.. some day when I have time and stuff :)

  4. janko Says:

    “little lime” = “little time”

Leave a Reply