Test-Driven Language Study

I learned Perl and Python by reading a lot of other people’s code, and by writing lots of small programs (and a few bigger ones). When faced with a “how do I make the language do…” problem, I’d fumble through a growing collection of scripts looking for that one place where I’d solved a particular problem before. Having a big collection of prior solutions is handy, but searching is problematic. Some patterns aren’t amenable to grep.

I’ve been playing around with Ruby (and the Rails framework) for several months, and have decided that it’s time to have a serious go at the language, using the the “Pick Axe” book as a guide. The pile of experimental scripts was beginning to grow again, until Mike Clark provided the transforming idea: Capture knowledge about how a language works by writing unit tests. In this case, one really big file of unit tests.

The idea is stunning in its obvious simplicity.

After an evening of digging through my pile of Ruby experiments, collecting up the useful pieces into a set of unit tests, I have a file with just over 100 unit tests, divided into categories like “tests about strings”, “tests about numbers”, and so on. Another evening’s work should double that number. Now, much of what I learn about Ruby will be captured in one easily searchable place.

I did encounter one anomaly, which I’ve boiled down to a simple test case.

  require 'test/unit'
  class TestUnitTest < Test::Unit::TestCase
    def testAssert
      assert true
      assert not false      # syntax error
      assert(not false)     # syntax error

After scratching my head at this for a while, I took it to the #ruby-lang IRC channel, where the resident experts pondering it and announced that it’s a problem in the implementation of Ruby’s parser, and that the workaround is to write

      assert((not false))

I wouldn’t have guessed that. But now I’ve captured the problem and its workaround in a unit test.

The Unix Clock Achieves Final Unity

Here’s one of those one-in-a-lifetime Geek things*:

  % perl -e 'print time, $/'
  % perl -e 'print time, $/'
  % perl -e 'print time, $/'

Now how cool is that?

In theory, I retire the day before the Unix clocks wraps, though judging from the number of old COBOL programmers who found re-employment during the Y2K run-up, I might land some consulting work fixing old Unix apps.

* The Unix clock counts the number of seconds since January 1, 1970 at 00:00 GMT. Due to an accident of history, the number of seconds in Unix time is limited to the largest number that can be represented in a 32-bit integer. That number of seconds takes us to January 19, 2038. Then, *poof*, Unix boxes worldwide burst into flame, and civilization grinds to a halt, just like what happened when Y2K hit. Today was the last day that the number of seconds in Unix time can be represented by a string of 1’s.

Late-Night Configuration Problems


  • Install Fedora Core 3. Turn off a bunch of services. done
  • Setup Samba and move a bunch of stuff off of other boxes. done
  • Turn on and configure Apache. done
  • Configure the router to port forward HTTP and SSH to the new box. Test. done
  • Setup a skeleton “nothing to see here” web page and test. done
  • Setup some other random web stuff and test. done
  • Get dynamic DNS set up through dyndns.org, and teach the router about it. Test. done

Picking up the story again last night at 1 AM:

  • Setup and configure MySQL. done
  • Migrate databases off of the old box. done
  • Generate SSL cert for Apache, restart, and test locally. done
  • Setup a virtual domain for dynamic DNS. Test locally. done
  • Configure the router to also port forward HTTPS. Test… Connection refused. Hm… Double-check the router to make sure I didn’t get dyslexic with the HTTPS port number. Nope. Check the httpd logs. Nothing. Restart Apache and try again. HTTP works; HTTPS doesn’t. Triple check everything. Nada. wtf?

The punchline, found at 2 AM after much flailing, was in the firewall rules file, /etc/sysconfig/iptables, which I’d touched once to get Samba working, and then forgot about. The FC3 install had ports unblocked for HTTP and SSH, but not HTTPS. Go figure. Add a line to support tcp on port 443, restart iptables, and test. Ah. Much better. Now I can sleep the sleep of those who can securely serve up a “nothing to see here” page from a home linux box.

Backhoes and their fellow travelers

Our phone and DSL where out on Friday and much of the weekend, along with the rest of the neighborhood. On Friday, one of the SBC repair people told us that the lines had been cut during trenching. I talked with another repair guy today, who said that it’d been the cable company doing the trenching. “They do this too us all the time,” he said. “We’ll have it all fixed in another day or two.”

I wonder what percentage of our monthly cable bill goes to covering stuff like this.

This Week, I Am Not a Writer

Writers write. This week I’m doing lots of things–cleaning my study, reconfiguring the home file server (again), and so on–but writing isn’t one of them. This week I am not a writer.

Double Your Memory, No Party Required

Adding memory to computers used to merit a party.

Many years ago, when I was at College, adding memory to computers was a Very Big Thing. There were only a handful of computers on campus. The two bigs ones had their own rooms. When we added a meg (256K of 36 bit words) of memory to our PDP-10, the memory arrived by truck in a box the size of a refrigerator, and took a week for two technicians to install (and we had to recompile the operating system). The new memory had its own box, with rows of blinking lights behind blackened glass. It looked cool. We had a party to celebrate.

Now, I click a few times and type in a credit card number, and two days later UPS delivers a small cardboard box with a half gigabyte of RAM. It takes five minutes to install, including rebooting. No party. It’s not that the fun has gone away; it’s just migrated to follow the bleeding edge.