Why Ruby is an acceptable LISP

Eric Kidd has an interesting post entitled “Why Ruby is an acceptable LISP”.

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.

Programming Ruby: The Pragmatic Programmers\' Guide, Second Edition

Multiple dispatch in Ruby

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…

Continue reading

Setting up Ruby on Rails to work with Apache and FastCGI

Up until today, I had only been running Ruby on Rails apps inside the built-in WEBrick web server, which is really slow.

Today, I set up my Rails apps to work with Apache. If you just run them as CGIs inside Apache, this is also really slow, so I went a step further and enabled FastCGI.

This web page and this other one helped a bit, especially in figuring out how to get around the missing fcgiapp.h error message.

Getting your feet wet with Ruby on Rails

Ruby on Rails logo

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:

  1. 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”.
  2. Execute rails <app_name> to have Rails generate a directory for your application with 11 subdirectories and lots of files already filled-in for you.
  3. Edit config/database.yml to point to your database.
  4. Execute ruby script/generate scaffold <model_name> to generate a bunch of code that handles New, Show, Edit, and Destroy operations. model_name is your database table but with a capital letter and not plural (e.g.: “Bookmark”), which I found to be weird and inconsistent.
  5. Execute ruby script/server to fire up a WEBrick server on port 3000. It logs to stdout so it’s very easy to see your errors.
  6. Point your browser at http://localhost:3000/<controller_name> and observe that you have a working application! (controller_name is like your database table, lowercase and plural – e.g.: “bookmarks”).
  7. Customize and extend the pre-generated code in the app directory. Ruby code has a .rb extension and HTML templates have a .rhtml extension and live in app/views.

Link

Books on Ruby on Rails from Amazon.com

Agile Web Development with Rails : A Pragmatic Guide (The Facets of Ruby Series)Rails RecipesProgramming Ruby: The Pragmatic Programmers\' Guide, Second Edition