Choose names that clearly express their purpose and avoid patterns that can lead to confusion or bugs. Names should be self-documenting and unambiguous in their meaning.
Key principles:
IsKnown()
instead of !IsUnknown()
to prevent logical errorsattempt_number
starting from 1 vs retry_attempt
starting from 0)_src
from public-facing namesASSESMBLER_WITH_C_PREPROCESSOR
→ ASSEMBLER_WITH_C_PREPROCESSOR
_is_versioned_shared_library_extension_valid
to _is_versioned_library_extension_valid
for broader applicabilityExample of avoiding double negatives:
// Confusing - double negative can lead to bugs
if (!command_wait_duration_ms.IsUnknown()) {
// This was actually a bug in the original code
}
// Clear - positive logic is easier to understand
if (command_wait_duration_ms.IsKnown()) {
// Intent is immediately clear
}
Example of unambiguous field naming:
// Ambiguous - 0 could mean "first attempt" or "field not supported"
int32 retry_attempt = 8; // starts from 0
// Clear - distinguishes between first attempt vs unsupported field
int32 stream_attempt_number = 8; // starts from 1
Enter the URL of a public GitHub repository