Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The style guide should include canonical example file(s) #145

Closed
andrewmains12 opened this issue Mar 25, 2022 · 1 comment
Closed

The style guide should include canonical example file(s) #145

andrewmains12 opened this issue Mar 25, 2022 · 1 comment

Comments

@andrewmains12
Copy link

The style guide is nicely written, and (afaict) unambiguous. However, it can be a bit hard to piece together the entire picture just from reading rules (even with examples). In particular, I found the function grouping and ordering section hard to grok: https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering

Proposal: let's add a "kitchen sink" example file containing a large subset of the style guide's rules, with comments. I think this would be most helpful to elucidate the "file structure" rules, e.g. ordering of types, variables, methods, etc.

A brief example:

package example

// Consts go at the top (reference here)
const (

)

// Next vars (reference here)
var (

)

// Next type defs
type Foo struct{

}

type Bar struct{

}

func NewFoo() *Foo {
  return &Foo{}
}

// Group methods by receiver
func (f *Foo) DoFooThing() {
   // maybe throw in some examples r.e. early return etc here.
}

func (b *Bar) DoBarThing() {

}

// Freestanding functions are last. https://github.com/uber-go/guide/blob/master/style.md#function-grouping-and-ordering
func helper()
@andrewmains12
Copy link
Author

On second thought, this can probably just be done within the ordering section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant