Open
Description
I (and several other Uber engineers) are a bit confused by the https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering section, specifically for the case where there are multiple types in one file.
Should it be:
// All type defs at top.
type something struct{ ... }
type somethingElse struct { ... }
func newSomething() *something {
return &something{}
}
func (s *something) Cost() {
return calcCost(s.weights)
}
func newSomethingElse() *somethingElse() {
return &somethingElse{}
}
func (s *somethingElse) DoOtherThing() {
}
func calcCost(n []int) int {...}
or:
// Type defs near methods
type something struct{ ... }
func newSomething() *something {
return &something{}
}
func (s *something) Cost() {
return calcCost(s.weights)
}
type somethingElse struct { ... }
func newSomethingElse() *somethingElse() {
return &somethingElse{}
}
func (s *somethingElse) DoOtherThing() {
}
func calcCost(n []int) int {...}
The style guide states:
Therefore, exported functions should appear first in a file, after struct, const, var definitions.
which makes me assume that "all type defs" at the top is correct, but it's not 100% clear from the example.
We should clarify this situation in the style guide (or, if the style guide has no opinion on it, state that as well).
Metadata
Assignees
Labels
No labels
Activity