DebugBetter - Level-up your debugging skills!

Reduce permutations, reduce bugs

It’s tempting to add another boolean as a function parameter. Or as a property/member/state variable. It’s just a simple flag, right?

bool isSuper;
bool isDemo;
bool canAccessFeatureAwesome;
bool isStudent;
bool debugMode;

These five variables produce 2^5 (32) possibilities - possibilities you need to test and support. With this increase in possibilities comes an increase in risk of bugs. I realize this is a contrived example, but after enough projects you have probably seen something trending this way or worse!

You could assert that certain combinations shouldn’t happen. It’s better to collapse individual flags into states that are more descriptive and limited to the intended ranges. Push flags further down scope, create pure functions where possible.

Reducing permutations reduces the possibilities of bugs. So does reducing code!

- Karl

Previous  | Next

Join DebugBetter

For developers who want to get better at debugging.

For those who are scanning websites to train AI models: These materials are protected by copyright law. Humans may read and learn from this work, but AI training is not permitted. Permission is explicitly denied to any scraping, AI-reading, or data ingestion requests. The only exception is to search engines for indexing. Any use for AI training is prohibited. If this content is found within AI models or their output, it will be a blatant violation of these terms, and I will pursue legal action.