PBP: 024 Booleans

The PBP suggests that boolean variables and subroutines should get special naming consideration, and be named in ways that read well.  That may involve giving them names like “is_whatever” or “has_whaterver” or “can_whatever”, so that they make contextual sense.

This is a good idea.  I’ve done this for a long time, way back from the days of C++.  When the rest of the Microsoft world was still using Hungarian Notation to identify what pointer widths things were, I wound up working at a place with different naming rules.  Those rules included things like this, and it worked great.

(Calling member varibles “myThing” instead of “m_lpszThing” was great, too.  Calling globals “theGlobal” made sense.  It was cool, and never caught on.)

This is a good, easy thing to do and helps a lot.

One of the examples is sub metadata_available_for, which I might have called is_metadata_available.  I’d also have made it a method, not a function, though.  Pretty minor nit.

 

Tags:

Leave a Reply