golang-pitfalls-control-structures

Installation
SKILL.md

Golang Pitfalls: Control Structures

Source material: mistakes #30-35 from 100 Go Mistakes and How to Avoid Them (teivah/100-go-mistakes).

Apply these rules when writing Go loops and control flow.

30. Elements are copied in range loops (#30)

  • The value element of a range loop is a copy. Mutating it does not mutate the collection element (unless the element/field is a pointer).
  • To mutate structs in a slice: access via index s[i] (range or classic for).
for i := range customers {
    customers[i].age = age // works
}
for _, c := range customers {
    c.age = age // no-op on the actual element
}
Installs
2
First Seen
9 days ago
golang-pitfalls-control-structures — fabianoflorentino/golang-agent-skills