Rants on software, computing, and any other topic I feel like.

Tuesday, January 04, 2011

Switching on Boolean Conditions and Flags

I just posted an article over at CodeProject.com about what I call a boolean switch or switch flags (as the library I wrote is called). I've thought a lot about it over the years and implemented in a couple ways. It reduces the complexity of nested if statements. Basically, it allows for code like this:

switch_flags_2(a > b, c != d)
case flags_2(T,T):
// only execute when "a > b" and "c != d"
case flags_2(F,X):
// execute when "a > b" is false

Labels: , ,

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?