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.

Published 06 April 07 06:32 by etayrien

Comments

# Shadders69 said on May 18, 2007 6:25 PM:

Hello, First Post and all that,

Why not call the method IsUpdating or IsUpdated?

No need for an enum, the method name tells you if its finished updating :)

Shad.

Anonymous comments are disabled

Search

This Blog

Tags

No tags have been created or used yet.

Syndication

Page view tracker