Follow Go's idiomatic control flow patterns to improve code readability and maintainability. Key practices include: 1. Prefer early returns over else blocks
Follow Go’s idiomatic control flow patterns to improve code readability and maintainability. Key practices include:
Example - Before:
func inferThinkingOption(caps *[]model.Capability, runOpts *runOptions, explicitlySetByUser bool) (error, *bool) {
if condition {
// success case
} else {
return errors.New("error"), nil
}
}
After:
func inferThinkingOption(caps *[]model.Capability, runOpts *runOptions, explicitlySetByUser bool) (*bool, error) {
if !condition {
return nil, errors.New("error")
}
// success case
}
This approach:
Enter the URL of a public GitHub repository