Use distinct variable names that reflect their types to avoid confusion and make code intent clearer. Avoid reusing the same variable name for different types within the same scope or related functions.
This prevents confusion when tracking values as they pass through functions and makes the code more maintainable. When variables of different types serve similar purposes, use descriptive suffixes or prefixes that indicate the type.
Example from the codebase:
// Bad: Same name for different types
let executable: bool = file.is_executable();
let executable: FileExecutableFlag = FileExecutableFlag::from(executable);
// Good: Type-specific names
let executable: bool = file.is_executable();
let exec_bit: ExecBit = ExecBit::from(executable);
Other examples:
handle
instead of val
for same_file::Handle
objectsremote_branch
instead of ambiguous origin
for branch parametersremote_url
and push_url
when both are URLs but serve different purposesThis practice is especially important in functions that transform data between types or when working with similar concepts at different abstraction levels.
Enter the URL of a public GitHub repository