Choose variable, function, and parameter names that clearly communicate their purpose and avoid confusion. Names should be descriptive enough that their intent is obvious without requiring additional context or comments.
Choose variable, function, and parameter names that clearly communicate their purpose and avoid confusion. Names should be descriptive enough that their intent is obvious without requiring additional context or comments.
Key principles:
file_content
instead of file
when it contains file contents)file
and path
that could mean the same thingExamples of improvements:
// Poor: confusing parameter names
fn string_reproduces(file string, pattern string, command string, path string) bool
// Better: clear, distinct parameter names
fn string_reproduces(file_content string, pattern string, command string, file_path string) bool
// Poor: abbreviated, unclear method name
fn (mut c DiffContext[T]) gen_str() string
// Better: descriptive method name
fn (mut c DiffContext[T]) generate_patch() string
// Poor: misleading function name vs return type
fn (mut g Gen) get_enum_type_idx_from_fn_name(fn_name string) (string, ast.Type)
// Better: name matches return type
fn (mut g Gen) get_enum_type_from_fn_name(fn_name string) (string, ast.Type)
This approach reduces cognitive load for code readers and makes the codebase more maintainable by eliminating ambiguity about what variables and functions represent.
Enter the URL of a public GitHub repository