Reading up on MVC, part 1: Ruby on Rails

masak on 2009-06-26T20:11:31

Hello, don't mind me. I'm just going through a few MVC frameworks to see how they differ and how they're alike. I need the knowhow to create an MVC for Web.pm. Right now, my plan is to examine Rails, Catalyst, Django and Jifty. I'll write down my impressions of each of the in some kind of list, for future reference. Basically the only way you'd want to read this is if you want to laugh at how little I know about MVC frameworks.

Here's the list I got from watching this screencast:

  • Man, the Ruby folks sure can make a beatuiful screencast!
  • Rails uses scaffolding. I've heard not all people like scaffolding, but it does look kinda convenient to my untrained eye.
  • Partial templates are called, logically, "partials". They bind smartly with variable names somehow.
  • Different output formats are really easy to add. XML, JSON, Atom...
  • A blog is a really nice example for an MVC framework screencast, because it's just a list of posts, each with a list of comments.
  • Rails can add authentication through before_filter.
  • Hm, clearly the strength of Rails comes largely through the keywords it introduces. Wonder if it uses monkey typing for that?
  • Rails has Routes! Maybe this is my chance to finally understand ihrd++'s Routes, which I never really grokked.
  • Controllers do things like index, show, new, update and delete. Probably related to CRUD somehow.
  • That 'debugger' trick is fantastic! One of those features which you feel can't be just hot air.
  • AJAX is fairly well integrated, though I'll be danged if I understand exactly how. Looks like magic to me.
  • Did I hear that right? "rjs is just a way to generate JavaScript using Ruby." Wow.
  • There's graceful fallback from JS to non-JS.
  • There's built-in automated testing.
  • The console seems like the debugger again, but without the breakpoint. Yes, I can see how that might be very useful.
  • Never once do they explicitly say 'the database' in the screencast. They say the word 'database-agnostic' once, and 'table' and 'column' a few times, but most of the time it's just 'model', 'view', 'controller'. Seems like the abstraction is largely intact.

Um. Well, in summary, that cool-aid sure seems to have an effect on me. I'll leave the comments open so that you people can tell me how Rails, despite all appearances, is really bad for your teeth and leaves skid marks on your puppy.

Next up: Catalyst.


Also...

draegtun on 2009-06-26T21:02:07

Have a look at Mojo. I recently read somewhere that the author (sri) had written it with a Perl6 (port) in mind.

Re:Also...

sri on 2009-06-26T23:31:39

Thats correct, we have a full featured HTTP 1.1 stack ready to be ported to Perl6. (also including a Rack layer on the server side)

Don't forget Rack based frameworks

yft on 2009-06-26T21:29:05

Don't forget the simple but effective 'Rack'. I find Rails and Merb etc to be too complex. If you need mod_perl like raw power, Rack is the way to go.

I wrote about it at http://blogs.yellowfish.biz/2009/our-application-development-setup-and-why-json- rocks/

Re:Don't forget Rack based frameworks

sri on 2009-06-26T23:40:34

I don't think you can compare mod_perl and Rack (both Rails and Merb are based on Rack these days btw.). Rack is all about running your code on different HTTP servers using a unified api, while mod_perl gives you the power to hook into the guts of Apache and change low level logic.

Re:Don't forget Rack based frameworks

draegtun on 2009-06-27T08:42:03

Well if you like Rack then you should be looking at HTTP::Engine or Mojo for Perl equivalents.

Re:Don't forget Rack based frameworks

masak on 2009-06-29T12:20:23

It might please you to learn that Web.pm aims to have a full port of Rack at its core. The idea is that people should be able to choose the level of abstraction they want to build their web app on. The levels are something along the lines of:

  • A minimal setup. (Rack.)
  • Templating.
  • MVC.

That last level is the reason I'm investigating MVC frameworks at present.

Re:Don't forget Rack based frameworks

sri on 2009-06-29T13:04:26

If your aim is to have a full Rack port maybe you should call it Rack or Web::Rack? Web.pm seems a bit too generic, after all there will be alternatives and they'll need a namespace too.

Re:Don't forget Rack based frameworks

masak on 2009-06-29T14:50:08

Noted.

For various reasons I'm not inclined to discuss the naming of Web.pm via a blog commenting system. I'll happily move the discussion to IRC or email, though.

Re:Don't forget Rack based frameworks

yft on 2009-06-29T15:16:07

That, my dear friend, will be awesome. Mod_perl is great but a web server agonstic and low level web framework like Rack or Servlets will make Perl shine again (and a bit of slick marketing!).

Scaffolding...

sri on 2009-06-26T23:25:05

Scaffolding sure looks amazing in Screencasts, but what you shouldn't forget is that the ORM agnostic Merb was pretty much about to beat Rails when they decided to merge both projects.

Re:Scaffolding...

masak on 2009-06-29T12:25:23

I know nothing about Merb, except that it was merged with Rails. In particular, from your comment I still am no wiser as to why scaffolding is bad, or why Merb was successful due to its lack of scaffolding.

Guess I'll have to read up a bit on Merb. Or what's left of it. :)