A couple of points on that PDML + Twitter mashup. First, yet another homily saying “Please unit test”. Second, some commenters wanted to see the code even though it’s trivial, and I found a reason to agree.
TDD · I was just sketching this in on a lark, so why, I thought, go all bureaucratic with unit testing? Mea culpa. Mea maxima culpa. A PESO came along that broke the code, so I fixed it and broke some other code. On that path lies madness. So I did the right thing: looked at the code, realized that if it were to be testable, it needed to be refactored, and hey, the refactoring made it better. And, bloodied but wiser, I wrote the tests for the refactored methods before I wrote the methods. Then I just bashed out the methods in the simplest possible way and fixed a couple of obvious problems and I was done.
It took less than an hour. And if I’d done it the right way the first time, it would have taken less time. Yes, I know all the good programmers out there already know that; I’m just publishing this to punish myself.
The Code ·
A couple of commenters wanted to see the code. I thought it was too dumb
and trivial to publish, but then I noticed that
pdml-twit uses a
couple of the new i18n thingies in Ruby 1.9, which might be useful as an
example to someone. First
of all, it begins with:
# encoding: utf-8
Then it has some non-ASCII characters in the source code, and callouts to
String#bytesize because the target is 140 bytes. For
example, one random line:
extra = " “” ".bytesize
So, here it is: pdml-twit.tar.
Comment feed for ongoing:
From: Dustin Whitney (May 05 2008, at 11:47)
So what are your feelings on TDD? Do you like the test-first approach? In my own coding, I don't really like to write the tests first, and I don't mind if my code is kind of a hack job until I get it working; then I clean it up and write my tests. When I do that, I can see what changes I need to make to make my code more testable, and I don't see how I could have the foresight that the hack job gives me before I write any code using the test-first approach... my 2 cents