Apr 21 2011

Boolean Arguments

I find that boolean arguments don’t read that well when revisiting the code a little later.


This is easily fixed with languages that allow keyword arguments, like Python:


However, in languages without, such as Java, I’ve found it preferable to create two constants for true and false, named for what they will be used for.

private static final boolean DONT_NOTIFY = false;
private static final boolean DO_NOTIFY = true;


It’s kind of like the suggestion in Code Complete to use Enums instead of booleans.

  • #programming
  • #java
  • #python
  • #booleans
  • #code style