PBP: 066 Negative Control Statements

The PBP simply states, “Don’t use unless or until at all.”  I don’t agree with the strength of that statement.

I find it much clearer in most situations to write “Unless Thing” than “If Not Thing”.  Especially true in the postfix cases where I feel if is tolerable.

Unless blocks can be a little less clear, but simple expressions are fine.  If you need to use extra parens just for the “not”, then unless might be right.  If it’s already very complex, the not and a regular if will be okay too.  It depends on the complexity of the statement.

Oddly, I don’t feel the same about until.  I would rather see “while Not Thing” than “until Thing”.  I used to use a C-like do { … } until (); block, but have gotten over it.

There’s a big sidebar (see page 99) that discusses this, and the conclusions there are almost exactly what I come to.  I do think it’s worth the effort, but that it can get confusing.

Leave a Reply