Archive for the ‘rails’ Category

Back to Writing + Why MVC programming rules, and Rails sucks.

Thursday, February 11th, 2010

I’m back.

There’s precious few of you around to notice, I gather.  According to my Google Analytics statistics, there are 100% less of you visiting the site than there were a year ago.  100% less might seem daunting.  It might seem like there’s NO ONE AT ALL actually paying any attention.  And with good reason, mind you – with my burgeoning programming work, my blogging time has fallen from ‘the thing I do on a nigh-daily basis’ to nil.  The time I used to spend carefully crafting my posts now goes into creating data models.

And yet, blog I must!  My creative side has been engaged, but in a completely different way than I’m used to.  I have to constantly be creative to overcome the hurdles that web apps keep throwing up in my path: figuring out how to do X when all I definitively know how to do is Y.  (Answer: Split the bottom of the Y with a hatchet to make the X.)  But that’s not writing, and it’s even different from game design, which has also lagged behind as Phase I of Being My Own Boss has come to fruition.  I don’t want to get my writing brain so rusty I need a crowbar to pry it open.

Steps need to be taken.

So back to blogging it is – it’s right under my nose every day, and I am paying for this website after all.

Assuming that there’s anyone still reading, let’s explore my latest epiphany: the Model-View-Controller paradigm of programming, and why it’s so freakin’ amazing – and how the Rails community is blowing it with helping other folks become better programmers.

MVC, if you’re not familiar, is just a way of thinking about dealing with a web application (or any application, really).  If you really want to get into the nitty-gritty, read this.  If you don’t really care, then just accept this notion: using MVC divorces all of the look-pretty stuff that goes into a web page (all the images and styling) from the actual engine of the site, which is also separate from all of the back-end mucking about with databases.

And I get it now.  I didn’t for a long time, but I get it now.  I understand why this is such a smashing good idea.  I’ve recently been working on some projects with long legacy histories, where the code was all cobbled together and strung out in one long chain of if-else statements.  And now I see MVC for the good that it can do.

I’ve known about MVC for a while, having been poking at Rails and trying to fire up various Rails projects.  But I’ll be damned – damned straight into the ground – if Rails isn’t the biggest pain in the ass to get working.  A large part of the problem is the Mac-centricity of the Rails community.  Rails screencasts are on Macs.  The best editor for Rails is Textmate – which is inexplicably Mac-only.  The very few attempts at Rails tools on Windows are either outdated or clumsy – even InstantRails, about the only Windows Rails development package worth mentioning, is nominally dead.

Now, I should mention that as I speak, I have a Mac Mini sitting on my desk for iPhone development, I own Textmate, and I have two VMWare Linux servers running.  I’m OS-agnostic to a very high degree.  But until Apple makes a laptop of similar power that retails for Dell-ish prices, my development core is in Windows.  That’s just how I have to roll.  (And don’t even get me started about the fact that you can’t roll OS X into a virtual machine – I’ll be here all day yelling.)

Surely the Rails community at large knows about this imbalance – and neglects it.  Maybe it’s even benign.  But I don’t think so.  I have a stack of books that talk about the Ruby Way, and by extension the Rails Way.  Rails discussion is replete with the ‘right’ way to do things.  Mind you – it’s all good advice.  Great advice, even.  But it certainly points up the one-wayism of the Ruby community, and I think that the Windows bias is part-and-parcel of that attitude.  And it’s a shame, really.

But luckily for the rest of us, there’s PHP frameworks like Zend, CakePHP and CodeIgniter (my personal favorite) – that I’m using in all sorts of projects (including an open-source project called Hermitage that will be up on Github soon).  CI implements (but doesn’t enforce like Rails does) an MVC architecture, and my coding is better for it.  As far as I can tell, the only real deficit to the PHP frameworks from Rails that I haven’t been able to overcome (yet) is the lack of ORM (object relation mapping) – having my objects in CI know, for example, that a user’s Cart has Items in it, and if I call for the Cart, I want the Items in it as well.  In Rails, you set it up when you create the object – in PHP, you need to explicitly write out this code, which takes time.

So get your head out of your buttocks, Rails.  I’m sure I’m not the only developer out here who wishes that Rails was easier to develop on Windows, and to deploy … period.  But my deployment woes will have to wait for some other rant.