DEV Community 👩‍💻👨‍💻

Discussion on: How Do You Name Your Boolean Variables?

dmfay profile image
Dian Fay

Hungarian notation is dead and good riddance to it, but formulating boolean names as isX or hasX does a lot for clarity.

610yesnolovely profile image
Harvey Thompson • Edited on
var hasGoodPoint = true;
var isMyConvention = true;

Also, I prefer not to pass booleans to (typically multi-argument) functions unless they are obviously expecting true or false (ie. property methods), so typically "can" or similar named functions:

This is okay:


But this is not so good:

someMethod("Thing", true);

Some languages have named arguments, so in that case it'd be better to say:

someMethod("Thing", canDelegate=true);

Alternatively use enums:

someMethod("Thing", Delegation::Allowed);