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.