May 23, 2008

Love/Hate: Ruby

I have a feeling I'm about to start another flame war (or at least I would if people actually read this blog).

I'm tired of Rails. For many boring things like writing simple SQL statements or things like that, Rails is great. But when you want to do something that Rails wasn't originally designed for (or designed to prevent) it is a big pain in the ass. And let's face it. The guys who made Rails are pretty smart (albeit some of them from what I've seen are getting a little big-headed) but they are still only human and cannot see the future. All computer technologies (especially where the Internet is concerned) go obsolete, and I think Rails is a bit to bulky to handle the huge Web 2.0 sites. Structure is both a blessing and a curse, it is great for making a good maintainable application, but when the problem calls for expanding outside of the framework it is a lot more difficult. Rails is too complex for the average programmer to tweak should the need arise, so it is usually easier to just dump it if it is being a burden. A simpler framework with a smaller footprint and smaller codebase would be much more desirable for a large site, so that if something needs to be changed, it can be changed easily and the framework is not holding you back.

Many of us know that there is much to Ruby besides Rails (at least we tell ourselves this). So let me now focus on the good and bad aspects of Ruby itself.

The Good:
You can do a lot in less code. It's wonderbar. I love using regexes and their handy little variables: $1, $2, etc. It makes the little scripts for manipulating files and text much easier. From what I'm told, Perl is even better for this. However I'm also told that maintaining Perl code is like stabbing yourself in the eye. So I stick with Ruby.
It's easy to get extensions. Just go "gem install myobscurelibrary" and you can usually get it.

The Bad:
Open classes. Shamefully, I have used them because they provide a very convenient way to patch a class that didn't quite have the functionality I wanted. However it makes maintenance a bitch. If you're reading code that somebody else made, you would expect that the method calls you know would do what they're supposed to do. But no, some dumbass could make String.split email their grandmother, and you would have no clue unless you happened to stumble across their code that did it. Instead, you'd be sitting there scratching your head wondering why the code you just wrote is failing horribly.
Slow/resource-intensive. I wrote a tiny little GUI app in Ruby that just displayed a window with some controls, etc. Very basic, I've done this with C++ and it runs way faster. With the Ruby one, you can see a noticeable lag.
I used RubyScript2Exe to "compile" the Ruby program into a single executable, which then produced an executable of 15mb. Tiny by today's standards, but for a itty-bitty little GUI app that didn't do anything, that's pretty insane. Wonder what the size will be once I tack a few more gems in there.

These are the main good/bad points that come to mind immediately. Ultimately I have decided that the best use for Ruby is for little scripts. Either maintenance scripts, or scripts for simple websites. Dynamic typing completely ruins Ruby for a large application, and the fact that it is interpreted rules it out for anything resource-hungry.
So my consensus is if it can be small and slow, use Ruby. Otherwise go for a different language.

2 comments:

Guillaume Theoret said...

About Ruby2Script.. sure it'll make a large executable for a small program but it's not going to increase linearly. There's a lot of stuff that needs to be included no matter what so the minimum size is going to be quite large like you noticed but adding a lot more stuff shouldn't make it a lot bigger, only a little bigger.

Re your other points: All absolutely correct =)

Rob Britton said...

Yeah that's why I said "tack a few more gems", since tacking on more source code probably wouldn't add too much. Again depends on the side of the program, but you probably won't have a huge codebase for a Ruby app anyway. Gems however might add on a fair bit more.