As it turns out, Ruby compares well as a functional language, and it fakes macros better than I’d thought….
Now, given a choice between a powerful language, and popular language, it may make excellent sense to pick the powerful one. But if the difference in power is minor, being popular has all sorts of nice advantages. In 2005, I’d think long and hard before choosing LISP over Ruby. I’d probably only do it if I needed optimized code, or macros which acted as full-fledged compilers.
Interesting presentation that compares how these frameworks fare against each other for very simple web apps.
Video and discussion at Joel on Software
I’ve been reading recently about Common Lisp and CLOS and I’ve been intrigued by their radically different approach to OO and some of their interesting features, one of which is multiple dispatch. Most mainstream OO languages don’t support multiple dispatch natively although one can sometimes pull it off with tricks (e.g..: for C++, check out More Effective C++ from Scott Meyers or Alexandrescu’s Modern C++ Design or this article from Dr. Carlo Pescio in C++ Report).
Ruby doesn’t support multiple dispatch natively, but there’s an add-on called the Multiple Dispatch Library (multi) that let’s you do it and it’s a snap to use. Even a Rube n00b like me had it going in 5 minutes…
Slides from a presentation from Ruby creator “Matz” about future enhancements in Ruby2 and Rite.
This short movie shows how easy it is to setup a new Ruby on Rails application:
Books on Ruby on Rails from Amazon.com
This article doesn’t teach you a lot about Ruby or Rails, but the nice part about it is that it shows you how easy it is to build web apps with Rails.
I went through his tutorial last night and looked at my watch before and after. Literally, it took only 20 minutes to build a MySQL-backed bookmark storage application and I spent a good chunk of that time trying to figure out why it wasn’t working for me at first (contrary to what the article advises, I had to launch the WEBrick server while in the “Bookmarker” directory) and trying to analyze what was going on behind the scenes. Pretty impressive that you can build an app that fast and without writing a lot of tedious “glue” code
Here’s a brief summary of the steps:
- Create a database (I used MySQL) and a table. Rails wants you to create a table for whatever object you’re trying to store with a plural name (e.g.: “bookmarks”) and wants it to have an auto-incremented integer primary key called “id”.
rails <app_name>to have Rails generate a directory for your application with 11 subdirectories and lots of files already filled-in for you.
config/database.ymlto point to your database.
ruby script/generate scaffold <model_name>to generate a bunch of code that handles New, Show, Edit, and Destroy operations.
model_nameis your database table but with a capital letter and not plural (e.g.: “Bookmark”), which I found to be weird and inconsistent.
ruby script/serverto fire up a WEBrick server on port 3000. It logs to stdout so it’s very easy to see your errors.
- Point your browser at
http://localhost:3000/<controller_name>and observe that you have a working application! (
controller_nameis like your database table, lowercase and plural – e.g.: “bookmarks”).
- Customize and extend the pre-generated code in the
appdirectory. Ruby code has a
.rbextension and HTML templates have a
.rhtmlextension and live in