3.2. Booleans
A special case can be made for subroutines that return boolean values, and for variables that store them. These should be named for the properties or predicates they test, in such a way that the resulting conditional expressions read naturally. Often that rule will mean they begin with is_ or has_, but not always. For example: sub is_valid; sub metadata_available_for; sub has_end_tag; my $loading_finished; my $has_found_bad_record; Again, explicit and longer names are strongly preferred. Compare the readability of the previous code with the following: sub ok; sub metadata; sub end_tag; my $done; my $bad; # and later... if (ok($next_record) && !$done) { # Ok in what sense? What is done? METADATA: while (metadata($next_record)) { # Metadata exists? Defined? True? push @metadata, get_metadata_for($next_record); last METADATA if end_tag($next_record); # Does this set an end tag? } } else { $bad = 1; # What's bad? In what way? } |