Clean code in Go
Go leaves layout to gofmt: tabs, and no line length limit. Names are MixedCaps, never underscores, and a capital first letter makes a name visible outside its package.
What does Effective Go ask for?
With Go we take an unusual approach and let the machine take care of most formatting issues.
source
From Effective Go.
What does cleaner Go look like?
func (s *store) Get_owner() string { return s.owner }
func load_config(path string) (*Config, error) {
f, err := os.Open(path)
if err == nil {
defer f.Close()
return parse(f)
} else {
return nil, err
}
}func (s *store) Owner() string { return s.owner }
func loadConfig(path string) (*Config, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return parse(f)
}Other languages
More on clean code: comments, functions, naming and the checklist.