Back to all reviewers

Keep code structure flat

docker/compose
Based on 4 comments
Go

Maintain code readability by minimizing nesting depth and using appropriate control structures. Prefer flat code organization over deeply nested conditions. When dealing with multiple conditions:

Code Style Go

Reviewer Prompt

Maintain code readability by minimizing nesting depth and using appropriate control structures. Prefer flat code organization over deeply nested conditions. When dealing with multiple conditions:

  1. Invert if statements to handle edge cases early
  2. Use switch statements for multiple related conditions
  3. Structure code to make the logic flow obvious

Example - Instead of:

if condition {
    if nestedCondition {
        for name, s := range items {
            if deeplyNested {
                // actual logic
            }
        }
    }
}

Prefer:

if !condition {
    return
}
if !nestedCondition {
    return
}
switch {
case condition1:
    // handle case
case condition2:
    // handle case
default:
    // handle default
}

This approach improves code readability, reduces cognitive load, and makes the code easier to maintain and debug.

4
Comments Analyzed
Go
Primary Language
Code Style
Category

Source Discussions