Maintain consistency in null handling patterns across the codebase. When multiple approaches exist for representing absent or disabled values, choose one approach and apply it uniformly throughout the project.
Maintain consistency in null handling patterns across the codebase. When multiple approaches exist for representing absent or disabled values, choose one approach and apply it uniformly throughout the project.
Common inconsistencies to avoid:
Example of improving consistency:
// Instead of mixing approaches:
private long numTargetRowsCopied = -1; // sentinel value
if (rowBasedChecksums != null) { ... } // null check
// Use consistent patterns:
private OptionalLong numTargetRowsCopied = OptionalLong.empty(); // Optional type
if (rowBasedChecksums.length > 0) { ... } // length check
This consistency improves code readability, reduces cognitive load for developers, and prevents bugs that arise from mixing different null handling strategies in the same codebase.
Enter the URL of a public GitHub repository