Friday, January 18, 2008

Ruby Screenshot of the Week #27: Task List

WARNING: This blog entry was imported from my old blog on (which used different blogging software), so formatting and links may not be correct.

I've posted a number of blog entries showing NetBeans quickfixes for Ruby. This helps you detect problems in code you happen to be working on, since it shows a yellow rather than green file status if there are warnings in the file. (The file status is shown on the right hand side of the editor pane, next to the vertical scrollbar).

Unfortunately, this doesn't give you an easy way to audit your code. If you want to find all potential problems in your code, you'd have to open each and every file and look for yellow editor annotations... Not a tempting task for projects with hundreds of source files.

No more. As of the latest NetBeans 6.1 development builds, the Ruby hints and quickfix functionality is integrated with the tasklist. All you need to do is open the tasklist window (Ctrl/Command-6 - the number, not F6, or find it in the Windows menu). The tasklist will scan the entire project - or indeed all open projects - or even just the currently edited file. The tasklist scope can be chosen by the toggle buttons on the left hand side of the window.

When you're working your way through the results, note that the tasklist responds to the Navigate | Next Error action (default bound to Ctrl/Command-Period). This will also warp the caret right to the editor location for the error, which means you can press Alt-Enter immediately to show the rule quickfixes, if any. One such quickfix is to disable a particular hint type, so if you don't like a particular warning you can suppress it by just turning off the rule.

I personally don't like the Output window occupying the entire IDE width. Luckily configuring the window layout is very easy - just drag the windows around to where you want them. In my preferred configuration, I drag the output-windows into the editor bottom such that you end up with a layout like this:

Note also that the tasklist isn't only hooked up to the quickfixes; it's hooked up to the error functionality too and any parsing errors in your project will be listed there, at the top of the list (since errors have a higher priority than hints and warnings).

Although you can disable hints as I've described above, you cannot turn off compiler warnings yet (such as the one about ambiguous parameters).

Anyway, I hope this will be helpful. Even if you're not a NetBeans user, perhaps you can try a quick audit of your source code with it. Get a 6.1 dev build here, open the IDE, choose "New Project", and then choose either a Ruby or a Rails project with existing sources. Point to your sources, hit Finish, and then open the tasklist and let it churn away. Send bug reports and other feedback here.

Saturday, January 5, 2008

Ruby Screenshot of the Week #26: Ruby 1.9 Changes - hashes and case statements

WARNING: This blog entry was imported from my old blog on (which used different blogging software), so formatting and links may not be correct.

Ruby 1.9 has been released. It's a "development" version meaning that you wouldn't want to use it in production, but now is a good time to learn the new ways of doing things such that migrating to Ruby 2.0 will be easier.

Via Ruby Inside, I read
James Edward Gray's recent blog entry
detailing the work he did to update his library to 1.9 - and a number of people leaving comments are also pointing out language changes.

One such change mentioned is case/when statements not allowing colon as a separator. (I don't see this in Ruby Changes Wiki - does anyone have a source for this?). Seems like a a good candidate for a Ruby quickfix:

There are a couple of available fixes:

The first one is just replacing the colon with a then:

The second fix is instead putting the statement on a separate indented line:

Another language change I found in Sam Ruby's post is that you cannot write hashes as lists anymore. Here's a quickfix for that - first the code, this is from webrick's httpstatus class:

The quickfix is attached to the first list entry in the hash:

And previewing the fix shows the following proposed edit:

As usual, the NetBeans Ruby forums can be accessed via Nabble here and Gmane newsreaders here (other feedback channels here).