Original Post
I came across an interesting problem today. I've entirely phased out "magic numbers" in my programs; haven't had one of those in at least 3-4 years (except for 0, of course). The reasoning, of course, is to avoid unreadable code: Ok. So onto something else that bothered me. Magic Booleans. I had a function: (this is rough prototype code, by the way, don't nitpick it) Okay, so that's all cool and all, but what about the callers of the code? They'll do something like this: The code is pretty readable... except for that boolean sticking at the end. I oftentimes find myself, whenever I see a boolean, wondering "what the F does that boolean mean?". So, I was thinking... would it not be more appropriate to use enums instead of booleans to make code more clean and robust? To me, this solution makes the code much more legible, and I think I'll prefer doing this from now on... but I was wondering what other people think? Is this too much extra work, or do you guys generally think the end result is worth it?
if( x == 86.4 ) // what the F does 86.4 represent?
{
// blah
}
public class EntityNotifier
{
public static void PreNotify( long entity, Notification notification, bool recursive )
{
Entity e = Database.Get( entity );
e.PreNotify.Notify( notification );
if( recursive )
{
foreach( long child in e.Children )
{
PreNotify( child, notification, recursive );
}
}
}
}
EventNotifier.PreNotify( roomid, leaveroom, true );
public enum RecursionState
{
None,
Recursive
}
<snip>
EventNotifier.PreNotify( roomid, leaveroom, RecursionState.Recursive );