Write for Others as for Yourself

Don's post about the Sellsian Approach is right on. This dovetails nicely with what I love most about Ruby: the ease with which you can give your fellow programmers a domain specific language instead of an API. Last week I found myself leaving a comment "for the next programmer" that looked like this:

  # foo must be a Hash of String to Widgets 

My gag reflex took over, and so a few minutes later I committed the following executable Ruby instead:

  invariant 'foo is a Hash of String to Widgets'

With regular expressions, instance_eval, and threequals, it was trivial to make invariant into a fairly general mechanism.