// Naming #Golang
Think Less
I love go
because I don’t have to think about a lot of stuff while working with it. There is just “one way” to do a lot of things. One thing which is still up for interpretation though is naming things (oh god).
There is a pretty strong exiting convention:
- Package names are singular: token, database
- Functions are verbs: Read, Process, Sync
- Structs are plain nouns: API, Replica, Object
- Interfaces are active nouns: Reader, Writer, JobProcessor
These conventions allow for less thinking on choosing names as well as easy commenting.
// Read from the thingy.
func Read(thing thingy) error { ... }
// Pool responsible for managing funds.
type Pool struct { ... }
The function and struct names flow easily into the documentation
I follow a few more rules to further limit the amount of thinking I have to do:
- Use single function interfaces whenever possible
- Just add a
er
suffix to the function name to name single function interfaces
This has a nice side effect of forcing the most thought into the function names and keeping them clear and concise, instead of fighting that battle very time I have to make up another name that isn’t manager
.