Select parameter and method names that accurately describe their purpose and behavior, avoiding ambiguous terms that can lead to confusion. Consider these guidelines:
Select parameter and method names that accurately describe their purpose and behavior, avoiding ambiguous terms that can lead to confusion. Consider these guidelines:
// AVOID: Parameter name doesn't clearly indicate truncation behavior
pub fn truncate(&mut self, max_len: usize, stride: usize, left: bool) {
// ...
}
// BETTER: Use an enum with meaningful names
pub fn truncate(&mut self, max_len: usize, stride: usize, direction: TruncationDirection) {
// ...
}
"first"
instead of "First"
)from_string
not _from_string
)// AVOID: Similar method names with different behaviors
fn add_tokens(&mut self) { /* ... */ }
fn num_added_tokens(&self) { /* ... */ }
// BETTER: Clear distinction in naming
fn add_tokens(&mut self) { /* ... */ }
fn num_special_tokens_to_add(&self) { /* ... */ }
When choosing identifiers, always ask: “Would another developer immediately understand what this name represents without looking at its implementation?”
Enter the URL of a public GitHub repository