2005-01-20

Rails is smarter than you (or, at least me)

I'm going back through the Rails tutorial that I mentioned last post, only using PostgreSQL 8.0.0 instead of MySQL this time, and discovered something very, very nice about Rails.

The tutorial (for those of you who haven't gone through it—and if you haven't, you should; it won't take long, and I can wait—has you create a database table for storing items on a todo list. There's a column called "done" of type integer; 1 means "done" and 0 means "not done". My first time through the tutorial I followed these directions, but this time I made the "done" column of type boolean because, well, it makes more sense and PostgreSQL has that data type.

Before, Rails presented the edit field for the "done" value as a text field. This time, with a boolean behind it, Rails presented it as a select list from which "True" or "False" can be chosen. In other words, Rails is smart enough not only to detect the table columns for itself, it's smart enough to realize that the possible values are constrained and change the default UI to something more appropriate.

Now, one could argue that for a boolean not null column, the UI element should really be a checkbox, but that would be nitpicking.

2005-01-19

On the Rails!

I just completed my first Rails webapp, using the tutorial Making a todo list. I highly recommend this tutorial to anyone getting started with Rails—it's very well written. I wish the author had left his name somewhere in it so that I could pay proper respect, but this is gonna have to do.

Unfortunately, I can't show you my new Rails app, because links to localhost won't work. :-) It's running on my laptop, so I'll bring it to the next KCRUG meeting. Maybe by then I'll have more Rails to show off.

2005-01-17

What Languages Fix

An aside: from Paul Graham, a list of programming languages defined not by what they are or what they do, but by what problem with other programming languages it's supposed to fix.

2005-01-14

Instiki

I don't know how I've managed to not find out about Instiki before tonight. (That's not quite true. I do know. I'm woefully behind the curve when it comes to Ruby.)

For those of you even slower than me, Instiki is a wiki that runs on your local machine. (I don't suppose it's limited to just local users, but I don't know if it's designed to scale.) When launched, it goes to the background, listening on port 2500. Access is through a web browser (as you'd expect).

I've been thinking that it would be nice to have something like this for a while. This should be handy for keeping notes for myself and such.

2004-12-30

Random Ruby links

Some stuff that has popped up in the last couple of days, that I thought might be of interest:



RPA Package Advisor

If you don't know what Ruby packages exist to solve some problem you're having—or, worse, you can't decide which package of several bets meets your needs—the Package Advisor can help.


This is a sort of review of packages, giving you the "best of" for common problem spaces. We try to include the major packages for each space, with a short overview of the pros and cons of each. For some problem areas, there is a single package that is considered "the standard" for Ruby, and only that single contender is discussed.

It's a Wiki page, so those of you who know Ruby better than I do are encouraged to add to it.


Method Check: defined?

A description of defined?, which apparently has the distinction of being neither operator nor method.


2004-12-10

First Pickaxe, Now Rails

Dave Thomas let slip yesterday that his next Ruby book will be about Rails.

Now "with juicy bits"

Thanks to Jarkko Laine (and apologies to loading the image from your website—either ecto or Blogger is preventing me from uploading it myself):



What's next? "Ruby—it's not just for breakfast anymore"?

2004-12-08

Ruby Katas

Speaking of Jim Weirich, he's taken up the challenge put forward by Dave Thomas and written some Ruby katas (programming exercises).

Deferring calculations in Ruby

It started with Patrick Logan: How would you implement spreadsheets as top-level programming objects? He's not talking about dropping a grid into your source file, but allowing deferred calculations. What he wants is the equivalent of something like this:



a = 10
b = a * 2
a = 15
puts b
>> 30

"Easy enough," I hear you say, "if you use a lambda (method object) for the value of b." Ah, but there are at least two wrinkles there. First, you need to write the value of b as a lambda, which requires more typing. Second, when you go to use b, how you use it depends on whether it's a constant or a lambda. The only easy way around the second wrinkle is to make all values lambdas, which brings us back to the first wrinkle. Patrick solves both of these problems by defining a Spreadsheet class that contains Cells that contain Formulas—all of which are smart enough to do the tedious stuff for you.


Fortunately (for those of us who aren't as fluent in Ruby as we'd like), Jim Weirich has provided a Ruby implementation.