Sunday, May 27, 2007

RubyWorks announced by ThoughtWorks Studios

ThoughtWorks Studios have announced the July 2007 release of RubyWorks, which is intended to be “a new products and support service for Ruby ... to help enterprises implement and use Ruby more effectively”.

It looks like the bundling of some material they've already used in-house (like JRuby) with Mingle, with products they've worked extensively on themselves, such as CruiseControl.rb.

Of course the payoff is the consulting services they hope to sell from this, and increased willingness by larger enterprises to adopt Ruby and Ruby on Rails.

Which OS for Ruby on Rails development?

I recently acquired a second hand laptop to allow me to play more with Ruby on Rails without ignoring the family - I spend over an hour a day on trains, so it makes sense to do more than just read during that time.

“My first instinct was to whip out the spare Windows XP Pro CD”
My first instinct was to whip out the spare Windows XP Pro CD I've got at home, but then I figured I should really poke around and see what others had to say about developing on Linux. ThoughtWorker Jake Scruggs has an interesting post comparing Windows vs OSX vs Ubuntu for Ruby/Rails Development. He makes some good points and basically kiboshed the idea of using Windows:
“I’m not going to mince words here -- try to avoid developing in Windows if at all possible ...”
Now most Rails developers I know of use Apple Macs running OSX; for example that was by far the most common laptop at the Ruby on Rails Oceania meeting I attended recently. So it was unsurprising to have Jake sing its praises, especially using TextMate, however I was surprised by this summation:
“Really the choice between OSX and Linux is mostly the choice between TextMate and IntelliJ (or Eclipse/RadRails). And, for now, I think TextMate has a slight edge. TextMate’s auto complete is a joy to work with while IntelliJ’s indexing makes for crazy fast searching.”
I've been using RadRails for Windows, so this got me interested. A couple of weeks later and I've settled in to using RadRails on Xubuntu 7.0.4 (Feisty Fawn).

Xubuntu is my first real attempt at personally using a Linux distribution as a primary desktop OS. I've had experience using Linux servers (no GUIs), so I figured I could always drop back to the command line if something broke and I've had to once or twice during installations. But overall I have been pleasantly surprised at how civil an experience it has been.

“But overall I have been pleasantly surprised at how civil an experience it has been.”
My main hurdle was getting the new Aptana + Rails IDE setup. That proved to be difficult, with few helpful instructions online. At the end of the day I fell back to the tried and true RadRails 0.7.2 release.

One of the nice things is that with Xubuntu I can run MySQL server, a WebBRICK web server, RadRails, a PDF viewer (with AWDWR open) and Firefox without using more than half of my 512 MB RAM and only occasionally pushing the 1.8 GHz CPU above 25%.

The hardest thing to get used to is the compartmentalisation of functionality between applications. Sometimes that's a minor delay as I find where I need to do something, like the hassle I go through to change my desktop, screensaver and power settings. It's one application in Windows, but three (or four!) in Linux. Other times it's a royal pain, for example when I find that I haven't (yet) installed the right application to do something - but it's not clear what I should install to fix the issue.

My recommendation? The Windows experience is a great one if you have background in it, the Linux one is smoother in some ways (installing gems, finding online help) but in other ways (application interoperability) is more jarring. I am enjoying the experience of Xubuntu on my little old laptop, but I would hesitate before setting up my main work machine the same way.

I have no opinion on the OSX option, but my experiences with Apple Macs have not been universally wonderful - others have compared OSX and Windows XP more graphically and with greater detail than I ever will ...

Friday, May 25, 2007

Currency formatting stuck in Rails' Views

I've been re-doing the Depot application tutorial from the excellent Agile Web Development with Rails book as I've updated it for the latest version of Rails in order to get a better handle on REST and other changes in Rails 1.2.3. I'm mostly doing it on the train in the morning and evening.

Anyway, as I go I'm challenging the approach given in the book to validate my own Rails/OO design knowledge. One area where I thought I could see a better way of doing things was with the formatting of the prices in the store view. Previously I had used sprintf() to give me a display_price facade attribute in the Product model that I could use for pretty (i.e. currency specific) versions of prices.

The number_to_currency helper method seemed to offer a great way of doing the currency formatting, especially given the helpful options it has for setting all sorts of specific details like currency symbol, separators for thousands etc. The tutorial showed it being added into the Store view, which is nice, but potentially could leave me with a whole lot of places to make changes if I wanted to internationalise the application (although the elements could be stored in constants). However when I plugged it into my Product model it threw a nasty error:
undefined method 'number_to_currency'
It turns out that this helper method is part of ActionView and so can't be used in models or controllers (the documentation I link to above has comments about that under it). The workaround is to use sprintf() within models or controllers. At least the database column is now automatically detected as a BigDecimal rather than a Float so my previous hack is no longer required.

So is there a problem with this? On the one hand, I can see that number_to_currency is all about creating a string representation of a number, and thus sits squarely within the world of views. On the other hand the DRY principle militates that we should have a single authoritative source of this information, without creating larger issues. In theory this means the model layer, although it is unclear whether you would restrict yourself to the Rails models or the underlying database objects.

My rule of thumb is to KISS it and use the Rails model when you know everything you write will be in Rails. If you expected to have non-Rails applications accessing the data (e.g. legacy .NET or Java code) then I would look at creating a view (less flexible currency styling) or stored procedure to act as the database source object for my Rails and .NET models.

Thursday, May 17, 2007

Rails Envy: Java meets Rails

The Rails Envy guys ("It's not the size of the app that matters, it's how you code it") have got some great mock ads on Rails vs Java and Rails vs PHP in the same vein as those Apple ads. Here is the first of their offerings:

Wednesday, May 09, 2007

Agile and Ruby on Rails thinking

I attended the Ruby on Rails Oceania meetup tonight and learned some interesting things about RDoc (PDF) from Tim Lucas, got some good pointers on how to involve customers in Agile projects (PDF) from Max Muerrman and lastly some great tips on geocoding in Rails (PDF) from Cameron Barrie.

[UPDATE: Got more details (like full names) from Tim's blog. Also Tim's got his slides up on SlideShare.]

I've been playing with Ruby on Rails to broaden my understanding of Agile development concepts and practices, and it's going well. The principles of the Agile Manifesto sounded good when I first read them over a year ago, but since listening to Jason Yip from ThoughtWorks talk about them they've come to life for me, so I will be doing a series of posts about them and how they relate to my experience in over 13 years of IT consulting and contracting.

It's also been nice to read about how Rails is finally getting some traction in the Enterprise arena, firstly through Thoughtworks delivering their project management application, Mingle on JRuby, which basically re-writes Ruby in Java. This means that we now have applications written in Ruby on Rails, but deployed on Java in the enterprise. Very nice.

Secondly we have Microsoft announcing the Dynamic Language Runtime, which allows projects like their IronRuby (a different beastie than Wilco Bauwer's). In an interview with eWeek one of the developers behind the DLR, Jim Hugunin explains how they developed the DLR:
Hugunin: Where this all came from is I joined Microsoft with IronPython, but I joined to make the CLR [Common Language Runtime] a better platform for dynamic languages. In some ways this is what we've been working on for the past two and a half years. The way that we did that is we started by building one real high-quality production implementation of a language, which was IronPython, and getting a lot of users to beat on it and make sure that we could do it well. Now that we have that one quality implementation we started saying, 'Well, how can we make more languages run well on the platform and make them run even better?'”

Monday, May 07, 2007

SQL Server: Is that Linked Server really up?

Recently I needed to fix a SQL Server 2000 stored procedure that called various stored procedures on remote database servers (again using SQL Server 2000). In this case it was splitting a centralised queue of tasks across the database servers that needed to handle each request. For centralised management of remote sites this makes a lot of sense. To do this it relied upon declaring each of these servers as a Linked Server (an entry in the sysservers table).

The problem we had was that when one of those database servers was down it held up the rest of the process because the main stored procedure immediately died as soon as it could not see the Linked Server.

I found a nice explanation of why this happens on the SQL Server Engine Tips blog. They mentioned this was a problem with SQL Server 2000:
“Due to lack of exception handling and implementation of OPENQUERY/OPENROWSET/OPENDATASOURCE interfaces it is not possible to do it cleanly.”
However, there is a new stored procedure in SQL Server 2005 called sp_testlinkedserver that will solve the problem. Wonderful!

Unfortunately SQL Server 2005 is not an available option, so I was pleased to see someone had left another solution to this in the comments section. has a sample stored procedure called usp_serverup that gets rid of the problem by using SQL-DMO to test the availability of the Linked Server. That gives us a tool we can use to test the connection prior to running the code that will down our SP. Now that is cool.

[UPDATE: The usp_serverup solution utilises OLE Automation (which is why it avoids the aforementioned problem), which means that the account running it must have sa privileges within SQL Server. That creates a major security issue, so we're falling back to making the Windows service that calls the stored procedure chunk its calls by site, thus insulating each site from the failure of other sites.]

Saturday, May 05, 2007

Norton 360: Should we tell him?

I came across the latest viral marketing campaign from Symantec Australia today, it's promoting the new Norton 360 home security/recovery suite using a YouTube video:
The ad is quite funny for an IT geek like myself, especially the 'wall of fire' reference to the firewall function (which is actually named after the physical firewalls in buildings that limit a fire spreading).The ad micro-site includes a competition to see if you can spot the two places where 360 appears in images on the micro-site, but not in the ad. For what it's worth my money is on the tennis racket and the cup (although the tennis racket shows a white blob on the end in the video, you can't tell it's '360' as well as you can in the photo below).

Anyway, I can't say much about the product itself, except that I like the idea of stopping IM viruses and online backup and it seems to have a nice user-friendly console:

For over a year I've been using McAfee's SecurityCenter product suite (now VirusScan Plus) and frankly finding it damn annoying. At one stage it was prompting me 4-5 times a browsing session to confirm that I was a registered user on the McAfee website, because it had downloaded a new virus definition, or a firewall update. Surely this is something that could have been remembered, or taken on trust?

I've now downgraded to just the anti-virus (which I get free through work) and am back to using ZoneAlarm for my firewall needs and relying on Gmail to scour my email for spam. I typically use Mozilla Firefox, so I get anti-phishing tools built into the browser.

With Norton 360 it looks like Symantec are maintaining Norton's reputation for usable security software:
“Based on your constructive feedback, we made a number of usability and performance improvements through the course of the beta program. In addition, we are making available an optional add-on pack for Norton 360 for anti-spam, ad blocking, parental controls and confidential information blocking. The optional add-on pack will be available for download by the end of March.”
For what it's worth, I would love to win this one and see if Norton 360 can sort out my security and data backup needs wihtout constantly interrupting my web browsing ...

Friday, May 04, 2007

Rails slideshows

There are some great Rails slideshows on SlideShare, here are some of my favourites:

Scaling Twitter:
“It’s Easy, Really.
  1. Realize Your Site is Slow
  2. Optimize the Database
  3. Cache the Hell out of Everything
  4. Scale Messaging
  5. Deal With Abuse”

Introduction to Active Record:
“I have never seen an Active Record implementation as complete or as useful as rails.”
Martin Fowler

Ruby on Rails Resources (RESTful development):
“Constraints are liberating (a straight jacket for your mind)”