Write code that clearly expresses intent through explicit patterns, simplified logic, and readable structure. Avoid unnecessary complexity that obscures the code’s purpose.
Key practices:
if condition { return true } else { return false }
with return condition
_ = function_call()
instead of just function_call()
when intentionally ignoring return valuesExample of improvement:
// Before: verbose and nested
pub fn (s Status) is_success() bool {
if s.status.is_success() {
return true
} else {
return false
}
}
// After: clear and direct
pub fn (s Status) is_success() bool {
return s.status.is_success()
}
This approach makes code easier to read, understand, and maintain by reducing cognitive load and making intentions explicit.
Enter the URL of a public GitHub repository