Create identifiers that clearly convey meaning through descriptive names and appropriate types. Two key practices improve code readability and prevent errors:
Create identifiers that clearly convey meaning through descriptive names and appropriate types. Two key practices improve code readability and prevent errors:
// Instead of raw primitives:
pub fn get_retention_period_cutoff_ts_nanos(&self, db_id: &DbId) -> Option<i64> { ... }
// Use semantic types:
pub struct UnixTimestampNanos(i64);
pub fn get_retention_period_cutoff(&self, db_id: &DbId) -> Option<UnixTimestampNanos> { ... }
// Prefer:
let last_snapshotted_wal_sequence_number = get_sequence(); // Clear purpose
// Over:
let last_wal_sequence_number = get_sequence(); // Ambiguous
let timestamp_ns: i64 = 1682939402000000000; // Unit 'ns' clarifies meaning
// Correct:
write_lines_total: Metric<U64Counter> // Unit-less counters end with _total
// Avoid:
write_lines_count: Metric<U64Counter> // Non-standard naming
These practices substantially improve code maintainability, preventing confusion and subtle bugs related to type misuse.
Enter the URL of a public GitHub repository