Follow Go’s idiomatic control flow patterns to improve code readability and maintainability. Key practices include:

  1. Prefer early returns over else blocks
  2. Return errors on the right in function signatures
  3. 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: