Laziness Pays Off

After we took a week off and I forgot a week, this is the first time I’ve touched Oaqn in about three weeks. So Play We All marches on, with me spending 3 hours of our 2-6 hour budget. I picked up where I left off on lazy updates and I have an exciting announcement.

Code

Automated tests have a great ratchet effect on progress. I’d forgotten what the code looked like and what was done when I left off a few weeks ago, but the tests exactly listed what was working and what was left to be done. Even more importantly, as I finished the last bit of functionality and tracked down an incredibly frustrating little type big.

So the code in my player model looks like this:

class Player < ActiveRecord::Base
  lazy_update :travel_time

  def lazy_update_travel_time old, delta
    old + delta
  end
end

Every column I want to be lazily updated needs to be listed in the lazy_update line and then get an updating method named lazy_update_column. Whenever I ask an individual player for its travel_time, the lazy update code will check when the last update was, call this method with the difference in seconds, update its own timestamp, and return that new calculated value.

It's a bunch of finicky little code making sure all the values are properly initialized and all these steps happen in the right order with the right values, so the implementation code is about 50 lines and the test code is about 80. I'll bundle it up as a gem for others (I'm looking at you, Luke) to use after it's gotten some real-world usage.

Announcement

Oaqn is now the first So Play We All Game to receive revenue!

Yes, by now we've all funded each other's development through missing deadlines and paying penalties, but Oaqn has made $10 directly from a player (who wishes to remain anonymous). They're thanked on the credits page but chose not to get the badge.

The lazy updates lay foundation for the first early gameplay, so the Visionary Donor badge is only going to be available for another week or two. I won't leave it up more than a week after there's basic gameplay in place, so if you want this exclusive badge, visit the Oaqn homepage now and donate.

And in any case, please vote for Oaqn in this week's poll. (Jim and Luke: I'm good for up to 6h this week.)

3 Responses to “Laziness Pays Off”