700 Ruby Hobos

It's been a while, so there will probably be a couple of posts coming in rapid fire, especially as Tuesday is going to land me with a nice 7 hour car ride to Canada (at least I'm not doing it alone this year).

A couple weeks ago, I knew I had to revive my old labtrack application at our lab, as everyone was getting confused about who had which machine, and for how long. When we had this problem about 4 years ago, I took a week, and built a perl application that would nicely manage it all for us. That fell into disarray a couple years ago.

Staring at the old code, I realized that if I was going to do this again, I needed to do at least the following:

  • Make it so new machines and network adapters could be added from the web interface
  • Actually automate the generation of dns and dhcp backing files from the database
  • Use sqlite instead of postgresql (just to take out one more moving part).
  • Do it in some sort of web framework, so I'd at least learn something in the process

After looking around a little bit, I decided that Ruby on Rails was worth trying, so I'd at least have an opinion on whether or not this "web 2.0" thing is total hype, or if there is some usefulness in it. For those that have been living in a cave for the last year, Ruby on Rails is "the new hotness" when it comes to web development. It is a very cleanly separated Model-View-Controller framework for the Ruby language, which has generators for many of the most common things you would do.

Verdict: Ruby on Rails does deserve some of its hype

Longer Verdict

It took me 2 weeks to build my Ruby on Rails app over the course of nights and weekends (not 2 hours), in that time I did read 250 pages of the Ruby on Rails book as well. For me, the hardest part of the framework was understanding all the implicit relationships between the MVC layers. It wasn't until the in depth section of RoR that it sunk in. I guess a lot of that comes from my own bad habbits, where naming wasn't always consistant between layers of an application. In Ruby, if you keep them very consistant, you get a lot for free.

Things I really like about Ruby in General, and Rails in specific:

  • Syntax is nearly Perl (regex operator is just like you expect)
  • Good parts of Python were pulled in (no semicolons, everything is an object even more so)
  • Bad parts of Python were not pulled in (no block ending sequence, no explicity new() method)
  • The interesting block callback that you use for things like sorting is very ruby, and I think very cool
  • Rails has lots of really sensible defaults, and high function macros like date_select input type
  • Setting validation criteria on your Models covers about 50% of error checking that you'd need in an application. And because it is so brain dead easy, you're likely to put it in version 0.1 of your code.
  • The RoR book enforces good habbits. They go out of their way to talk about SQL Injection (and how to prevent it), unit testing, and development vs. test vs. production environments.

Things the annoy me about Ruby, and Rails:

  • Documentation is scattered. If you don't buy the 2 books (Programming Ruby, and Ruby on Rails), you'll end up lost pretty quickly. Better free online documentation would be good. (As a perl guy, I have a high standard here, as perl comes with > 100 man pages that cover almost anything you'd ever want to know about the language.)
  • No equiv of 'use strict' like in Perl. Fully dynamic languages are all fine and good, but I feel like they miss the mark in not having some base level checks like "did you actually declare that variable?"

Overall, Ruby is definitely growing on me. And RoR is a much better (safer, better habbits) approach than random PHP that I've seen as largely the alternative in this space. We'll see how this first deployment goes today, then I'll decide if RoR has a place in my toolkit.