« May 2006 | Main | July 2006 »

June 2006

June 29, 2006

Prices in Cents

In the second edition of AWDwR, I changed the Depot application to store money in integral cents, rather than floating point dollars and cents. Some folks pushed back on this, saying it overly complicated the application.

This morning, while working on some code to migrate some legacy data, I bumped into a problem that boiled down to the following (on my PPC—your results may differ)

  dave[store/migrate 9:00:57] irb
  irb(main):001:0> Integer(77.85 * 100.0)
  => 7784

Obviously it’s possible to do rounding (although even that’s trickier than you might first code if you have to handle negative numbers).

I still feel that Rails should convert decimal(x,y) columns into BigDecimal format in Ruby, giving us scaled, exact, representations. Until that day, stick with integers for amounts that you need to be exact.

June 25, 2006

Rails Guidebook

RailsConf 2006 is in its final day, and I just realized that I hadn’t blogged on Rails Guidebook.

The Guidebook was a preconference event. For a day before the conference proper started, attendees got an introduction to all the stuff that’d be hearing about in the following days. It was a combination of a tutorial and a glossary. We didn’t charge. Instead, the cost of admission was a contribution to charity.

The Rails community raised over $8,000

This is wonderful stuff, and Mike and I thank everyone who made it possible: the Ruby Central folks who agreed to add a day to the agenda, Jay Zimmerman for organizing the facilities, the core team members and other experts who turned up to help, Mike and Nicole for doing all the Guidebook logistics, and, more importantly, the folks who turned up and contributed.

A Challenge

If you’re already organizing a conference, adding a guidebook day ahead of it isn’t a great incremental cost. So, here’s a challenge to conference organizers. Let’s start a tradition of these types of charitable events. Let’s make a point of sharing some of our success with others. Not only does it do some good—it’s fun.

June 24, 2006

Glue That Doesn't Set

Back in the old days of computing—those days where I could still see my knees when standing up—folks used to talk about languages such as Perl as glue languages. What did they mean?

Glue

Well, Perl is a great general purpose programming language. But it is exceptional at doing something that no previous language could do well: Perl made it easy to glue together other stuff. Data, programs, external systems—all these things could be integrated using Perl. Thanks to its integration with the underlying operating system, and its amazing support for text processing, Perl made a name for itself as an integrator par excellence. Want to take the last 20 lines of an error log, convert them to HTML, and upload the result to your web server? Perl could do that in a handful of lines of code. Need to screen-scrape a book's sales rank from Amazon and writing it into a local MySQL database. Perl to the rescue.

Perl let us glue stuff together. It was magic.

But there was a problem. Perl is a great language. It was my scripting language of choice before I discovered Ruby. But even on my most charitable days I could never really claim that these Perl programs were exemplars of readability. And, in turn, this lack of readability made it hard for me to pick one of them up six months after I'd written it and make some change—even small alterations could involve long periods of head-scratching as I tried to work out exactly what the entries in my hash of arrays of hash references actually contained.

As a result, I found that the longer it was since I last looked at a program, the harder it was to maintain and extend it. The programs effectively became less malleable and more viscous. It became stickier; I got mired in a gooey mess of details. Leave a program long enough, and I'd often decide to rewrite it rather than attempt some piece of surgery: the program had become totally inflexible.

The glue had set.

Now Ruby is also a glue language. Just like Perl, Ruby works and plays incredibly well with external data, resources, and programs. I can do everything with Ruby that I used to do with Perl—I can use it to integrate all kinds of stuff just as easily as I used to be able to with Perl. But, there's a major difference. I've discovered that, over time, my Ruby programs stay malleable and easy to change. Ruby is the glue that doesn't set.

Glue and the Web

That's all very well, but what does writing little utility scripts have to do with real-world web programming? A whole lot, as it turns out.

As we move into a world where the network is the computer, applications change in character. Rather than writing free-standing islands of code, developers are increasingly writing programs that knit together other, existing web resources. Want to annotate a map with pictures of famous landmarks? Maybe you'll want to use the Google Maps and Flikr APIs to carry most of the load for you. Want to let your readers know when their product has shipped? Why not generate the information as RSS and let their aggregator client do all the gruntwork of displaying the result? As we move forward, more and more of our applications will be less and less like one-man bands and more like orchestra conductors.

Our applications are increasingly becoming glue code. And, if that's the case, I'd rather write them using a glue that doesn't set over time.

June 23, 2006

Capistrano-Standing Room Only

Cap005_1

It was standing-room only at Mike Clark's Capistrano talk: one of the first talks at this year's RailsConf. Latecomers stole chairs from other rooms and fought their way to some free floor space to hear Mike talk about the way we deploy Rails applications.

I'd just finished giving the first keynote. One of my topics was making deployment in Rails easier and more amenable to corporate use. I suspect from the interest in my talk, followed by the overwhelming interest in Mike's talk, that deployment will be one of the hot Rails topics of the coming year.

Cap006_1 Cap007_1

June 14, 2006

Shipping Rails Recipes

rails recipes
The Rails Recipes books just came in from the printer, and we spent the last 3 days shipping the preorders. It's still a family kind of thing, and I took some pictures and made a wee slideshow (1.6Mb) so you can see what goes on. (If you're looking for the gerbils—they know better to get involved when there are heavy boxes around.)

Now in Beta

  • Programming Ruby, 3rd Edition
    Third Edition, Covering Ruby 1.9, now in beta
My Photo

Pragmatic Stuff

Photos

  • www.flickr.com
    This is a Flickr badge showing public photos from pragdave tagged with pragdave_badge. Make your own badge here.

Site Search

  • Google Search

    The web
    PragDave