Prompt
Follow Go’s idiomatic control flow patterns to improve code readability and maintainability. Key practices include:
- Prefer early returns over else blocks
- Return errors on the right in function signatures
- Use if statements instead of switches for single cases
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:
- Makes code flow more predictable
- Reduces nesting and cognitive load
- Follows established Go conventions
- Makes error handling more consistent