Archive for September, 2007

TagFlow Accepted as RubyForge Project

Wednesday, September 19th, 2007

TagFlow has been accepted as a project on RubyForge. It is just the project default page(s) for the moment, but it exists. Now comes the work of uploading the code, building Web pages, starting discussions, etc.

TagFlow is a very lightweight, flexible, and multi-lingual task/item/issue management system. It is an attempt to build something agile and adaptable to different styles. It uses tags to indicate priorities, task types (e.g., usecases, bugs, documentation), assignment to people, etc. It is nearing release 0.2. It has been hosting it’s own task-list/workflow since release 0.1.

TDD vs. BDD, Day 2

Wednesday, September 19th, 2007

For the release 0.2 of my current project, TagFlow, I intend to have complete Test::Unit and Rspec suites. I have been building the Test::Unit suite as I went along, so there isn’t much left to do. Last week I added the last of the features for the release and started refactoring the code, readying it for public release. Earlier this week I completed the refactoring and started building the Rspec suite. I probably will maintain both for a release or two and then settle on one approach.

I’ve found a couple of good tutorials, the RSpec project documentation and “Developing a Rails model using BDD and RSpec, Part 1″ by Luke Redpath. The latter is over a year old and the syntax is different now, but the ideas are good. I am starting to like the BDD/RSpec approach. Since the tests are run in the order in the file, each test can not test for behavior already tested. For example, if a test search should find exactly three matches, a prior test can test that searches succeed and this behavior check can skip that and just test for three matches. Whereas in the Test::Unit approach, the more complex test is essentially the simple test with an additional test. Typically tests have a half dozen asserts, the last one is what is actually being tested and the rest making sure that the last test is meaningful.

RSpec is still under rapid development and there isn’t yet integration (cross-controller) tests in the trunk. Test::Unit is fairly complete and stable. However, integration and experimental story support are in the RSpec development tree. Hopefully they will be usable by the time I’m ready to use them.

TDD vs. BDD, First Impressions

Tuesday, September 18th, 2007

Computer programming is always evolving. Several years ago I encountered automated unit testing (i.e, the many Junit, CXXunit, etc. frameworks). Having a good test suite covering your back is confidence building. I started using it on CPIA (a re-implementation of PIA, the Platform for Internet Applications, a Java Web app framework, in C) about half way through. Translating Java to C can be a bit tedious, but after building some patterns, habits, and tools, it becomes rather straightforward. However, bugs, especially memory management bugs, can persist for months. Since I started writing tests half-way through, they tended to be added top-down, i.e., written for the newest code with additional tests for the older, lower level code written as problems were encountered and fixed. The experience convinced me further of the value of a good test suite.

Since then I have progressed to writing the code, testing it by hand, and then writing automatic tests.

Test-Driven Development (TDD) turns the order around: write the tests, run them (failure expected), then write the minimum code necessary to pass the test. Then write more tests and repeat until done. It is a hard habit to develop, but I am beginning to see the value of writing the tests first. One reason is if it passes on the first try, then something’s wrong! Either one of your colleagues has already done the work, the test framework (or your understanding of it) is broken, or you aren’t testing what you think you are. (Quis custodiet ipsos custodes?, roughly, who guards the guardians?) If your tests always pass, your confidence that your back is covered may be rudely shattered.

Behavior Driven-Development (BDD) is sort of TDD with the push of “you should” replaced by the pull of “I expect the code to behave like this”.

To illustrate, in an application I am currently writing (TagFlow, coming to a RubyForge near you soon), in the list of tasks, the task description is shortened to just a single line.  In the task’s page, the full description is displayed. Recently when cleaning up code, I inadvertently shortened all descriptions in a misguided attempt clean up the API.  (The same template is used for both versions of task, I just missed that the description as well as the complete task object was passed to the template because the description may have been shortened by a higher-level template).

I fixed it, added some comments to explain the more complex API, and pondered whether to write some tests. It looked like they would be a pain to write and brittle.  Maybe more trouble than they are worth. I wasn’t likely to make that mistake again, was I?

However, from the BDD perspective, my course is clear. I should have an executable specification of how I expect the application to behave, even before coding it.  Focus on what first, then work on how.  So I am off to write a behavior specification using Rspec that indicates to a human reader the expected behavior and also tests for that behavior.

Lone Star Ruby Conference 2007

Friday, September 7th, 2007

The Lone Star Ruby Conference (LSRC) 2007 is happening! It’s inexpensive, volunteer run (well!), single-track, and quite good. My interest is primarily Rails, but every speaker, so far, has mentioned something useful. There are 199 people here. Sun sponsored the dinner – BBQ brisket or chicken, beans, cole slaw, and potato salad. There was an option for vegetarians. Much better than the usual.

Metasploit 3.0 is written mostly in Ruby. One of the chief developers gave a talk on it here. People shutdown their WiFi cards, nervously checked their firewall logs, etc. He hacked into a couple of machines he had access to while talking. Nice framework, scary capabilities.

One thing that startled me was that the vast majority of laptops here are Macs. Better than 90%. There may slightly more Windows laptops than Linux but there are so few it’s hard to tell. Plus the diversity of windows managers/desktops makes it difficult to be sure what Linux boxes are running.

Some of it’s very technical and some is just plain fun. There are some parodies of the Mac vs. PC videos with Ruby vs. Java, Ruby vs. PHP. Tomorrow night they will premier a Ruby vs. Python video.

The JRuby co-lead is about to give the keynote.

Oh, and nearly 200 laptops definitely bottleneck the single WiFi access point