Archive for March, 2007

March 23rd, 2007

Testy Confession

by Tim Cull

So I’m at SDExpo right now, and one of the classes I took was test driven development using Ruby on Rails. This is the point at which I have to make a confession:

I haven’t written a single test for my mystats project.

There, I’m glad I’ve gotten that off my chest. I have two very good excuses so I feel quite justified, but this week the second of those excuses fell:
1) I’m learning a totally new technology and can only learn so many things at once
2) I have no idea how to do unit tests in Rails.

I feel like I’ve started to get my Rails legs now and am transitioning from exploring to implementing, so the first excuse doesn’t hold much water any more either. So now I’ve got to suck it up and go back to write some tests. There are two immediate pieces of work I’m now going to have to go back and redo:
1) Drop my database named ‘mystats’ and create two different ones named ‘mystats_development’ and ‘mystats_test’
2) Throw out my DDL SQL script and replace it with a Rails migration.

I should have known to avoid this hassle, especially because the Rails documentation, books and blogs all took pains to point them out repeatedly, but I was learning so much new stuff that I wanted to stick with something I knew and just move on. I’ve walked away with the lesson reinforced yet again: “when in Ruby/Rails, do as the Rubyists/Railsies do.”

March 23rd, 2007

SDExpo Day 4

by Tim Cull

Day 4 I was surprised to run into someone else from my company here. He’s our resident test driven development advocate and had hand-picked Thursday because it had so many classes about it. The man can do truly unnatural things with JMock, and I mean that in a good way.

We started the day with a session on TestNG by Alex Ruiz. Our project is starting to reach the limits of JUnit so TestNG seems to be just what the doctor ordered. Some highlights:

  • It’s annotation based instead of inheritance and naming convention based.
  • It allows arbitrary grouping of tests together
  • It allows you to specify dependencies between groups and methods
  • It’s easy to write setup and teardown methods for suites, tests, classes and methods
  • It has a “JUnit” mode that lets you run existing JUnit tests alongside TestNG tests

Something else interesting I didn’t know before: JUnit re-instantiates your test class for each method it calls. So if you try to use a class-level instance variable, it’s not going to work. Not that you should anyway, but there it is.

Next we went to a session on emergent design through test driven development by Alan Shalloway. This class was awesome mostly because it gave me some ammunition to support a point I’d already been trying to make at work. Specifically, that one of the greatest benefits of test drivien development isn’t that you end up with tests, but that having to think about the tests first automatically leads you to good design, even if you’re not a good designer. He walked us through an example where just keeping testability in mind caused you to create an extensible and maintainable design.

Next we went to a class called “Advanced TDD”, but really all it was was a guy from Siemens talking about why he thought TDD was good. Really, we get it by now or we wouldn’t be going to a class called “Advanced”.

Also, I forgot to mention yesterday that I saw a presentation by Amazon about their S3 storage, EC2 “compute cloud” and their reliable messaging offerings. They sound pretty awesome, in particular EC2 charges only 10 cents per hour. That’s an entire server for only 10 cents! Great for times when you demand is really peaky and you need to scale (and de-scale. Is that a word?) very quickly.

March 21st, 2007

100 alternative search engines

by Tim Cull

Found this link recently to an article about 100 alternative search engines. Some of them are pretty neat.

March 21st, 2007

SDExpo Day 3

by Tim Cull

It’s been a stop-and-go day today. I had to do a 2 hour conference call in the morning, exactly during an “Agile development with, or despite, a global team” session which was a bummer because I was looking forward to that one.

I did make it to a hands-on, rapid-fire session on test driven development with Ruby on Rails by Kevin Clark. It was a great class, and I was especially happy to see just how much TDD had been baked into Rails from the start, from adding useful assertion methods, to database fixtures, to a pre-canned build file that runs tests by default (rake), etc, etc.

I went to a patterns session that was supposed to be about combining patterns together in groups, but started with so much elementary pattern overview stuff that I lost interest and left. The best thing I got out of that session was a reminder that a pattern is a problem, a context, and a solution *all together*. Trying to just pull one of those out on its own is not nearly as useful as considering that triplet together as a whole.

I also briefly went to a session on open source as a business model. Lost interest in that pretty fast, too, but I did come away with a real appreciation for how painful the proliferation of slightly-different open source licenses is for anyone who has to try to understand them.

March 20th, 2007

SDExpo day 1 and 2

by Tim Cull

I tried to post this yesterday, only to discover much to my embarassment that my domain registration had expired last week. Oops.

Anyways, I’m back at SD Expo, which is what started this blog in the first place. That first experience is what helped push me in a different direction in my career, away from pure management and back into hands-on technology.

Two disappointing changes from last year: the bean bag chairs are gone, it’s impossible to find an open electical outlet, and the (free) wifi is unusably saturated. On the other hand, some of the talks are exactly the same, at least in title, to talks from 2 years ago. Many are new, however, including an entire track for Ruby.

Yesterday, I went to a service oriented design talk by Michael Rosen in the morning. The most interesting thought that came out of that for me was the idea of dividing your services ecosystem into two tiers: a lower-level tier of utility and integration services, and a higher-level tier of business-level services. For example, you might have an Authorization service at the utility/integration level, or a facade for a legacy system at the utility/integration level, but you’d have a “Booking” service at the business tier. This allows you to make different choices about things like transport mechanism and granularity at each level. It also allows you to keep your business services level ‘pure’ and isolated from compromises you must make when integrating legacy systems.

In the afternoon, I went to a Java Security talk by Allen Holub in the afternoon. I’d hired Allen to do an object oriented design class at my company a couple of years ago that I thought was really good. His talk on security was pretty good too; the most salient thing I got from the talk is that the Java security apis really are hellishly complicated, it’s not just that they look that way. Previously, I’d thought that it was just because I didn’t “get it.” But in reality, they’re just too complicated, as I’ve found is the case with many Java APIs. For example, just as the connection string in JDBC contains a lot of vendor-specific parameters smashed into an ugly string, the factory methods in the security api also do.

Today so far I went to a domain specific language talk by Juha-Pekka Tolvanen. This one was one of the sessions I was especially looking forward to because it seems like such a big and obvious win. I came away from that talk with a good link to DSM resources, but with the disappointing news that where these languages tend to be the most successful is in embedded and product markets (like cell phones), where a vendor churns out lots of variations on the same basic product line. There was one example from an insurance company, though, so there’s still hope for me.

March 2nd, 2007

Things I wish I’d known

by Tim Cull

For my mystats Ruby on Rails project, I hand coded a SQL schema; if only I’d known then what I know now!
Rails has a cool feature called a migration, where you write basically a ruby class that describes your
database table and it does the rest for you, including versioning. So if you just want to add a column
you can create a migration to do that. If it turns out that extra column was a mistake, then you can
tell Rails to roll back just that change, no problem.

Anyhow, on my last post I was trying to learn how many-to-many relationships work in Rails. That
was a month ago, but hey, I had a birthday, my wife had a birthday, and we all had Valentine’s day,
kids got colds and ear infections here and there, so give me a break, ok? You people are such task masters.

I bought a book (Ruby on Rails Up and Running, Bruce Tate and Curt Hibbs) and read it on the bus.
Turns out it only needed about 2 pages to explain everything I needed about many-to-many. It’s that simple.

Another thing I wish I’d known, though, is that Rails (surprise, surprise) has a naming convention for
the mapping tables typically used in a many-to-many relationship. In my case, I have a table named
“people” and a table named “groups”. I’d created a mapping table called “person_groups” to map
between them, but it turns out the names have to be both plural and in alphabetical order, eg “groups_people”.
Oh, well.

Once I’ve done that, my Person and Group classes are this simple:

class Group < ActiveRecord::Base
has_and_belongs_to_many :people
end

class Person < ActiveRecord::Base
has_and_belongs_to_many :groups
end

Now I’ve got an application that allows me to create groups and view them from a home page. To get the
home page, I ventured into hand coding my own controller. I also need to have the concept of logging in and
keeping a current user in the session–I’m guessing there’s got to already be a package for that, so finding it is
my next set of homework.