Back to all reviewers

Use idiomatic Go flow

ollama/ollama
Based on 5 comments
Go

Follow Go's idiomatic control flow patterns to improve code readability and maintainability. Key practices include: 1. Prefer early returns over else blocks

Code Style Go

Reviewer Prompt

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:

  • Makes code flow more predictable
  • Reduces nesting and cognitive load
  • Follows established Go conventions
  • Makes error handling more consistent
5
Comments Analyzed
Go
Primary Language
Code Style
Category

Source Discussions