Optimizing for Readability

About a week ago, Shawn wrote a post about different types of code, and how he designs them. In a few categories, he mentioned optimizing for readability. Today OldNewThing has a post about optimizing for readability. It's an interesting read, and the bit about boolean function parameters definitely rings true with me.

The other day I was working on my GSE game, and I had a class with an Update method. The Update returned a boolean indicating whether or not the class was finished updating. The idea was when the object was finished updating, I could stop worrying about it, and I could remove it from whatever collection was keeping track of it. The problem was I could never remember what the boolean was supposed to be: true if you're done updating? true if you're still updating? In the end I gave up trying to remember, and I just made a custom enum:

 

 enum UpdateResult
{
      StillUpdating,
      Finished
}

 

Problem solved.