Monday, January 5, 2009

Reading old code

I am mostly terrible at reading old code, ESPECIALLY my own. I sort of stare and curse at it for a while, eventually it makes sense. Normally having runnable unit tests make it much easier.

However, I found some old ruby code of mine (a pre-historic simple rule engine, using YAML as the syntax - called "ruby rules"), and strangely it made sense (and I swear I have no recollection of writing it):

- rule: Foo
set: Driver, Vehicle
if: driver.age < 21 and vehicle.high_performance
then: reject application



And a programmatic rule:


#now lets try it out
rule = Rule.new :declarations => ["a", "b"],
:types => [String.class, String.class],
:condition =>"a == '42' and b == '42'",
:action => "puts 'PASSED RULE 1'"

So what does this mean? I guess people smarter then me are right - ruby is a really friendly language. At least following the popular conventions for it leads to code that you could read well into the future (even without the comfort of static type guarantees).