Names #33
Labels
No Label
Dev Ready
Issue Not Ready
Tech Debt
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: simplesystems/go-resources#33
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What's in a name?
Readability is the defining quality of good code. A good name is consistent, short, and accurate.
The greater the distance between a name's declaration and its uses,
the longer the name should be.
Use MixedCase (no snake_case).
Capitalize acronyms.
Avoid redundant names (runeCount in a func called RuneCount).
The perceived need for a longer name may be an indication of a need to refactor.
Names may serve as documentation in func signatures.
Avoid named return values. They may add documentation in some places.
Keep method receivers less than 3 characters. Use a consistent name across the type's methods.
Do not stutter on exported names (strings.StringReader).
Single method interfaces should be the method name with 'er' appended. If there are multiple methods, be sure to choose a name that is accurate.
Error types should have the suffix
Error
. Error values should have anErr
prefix.Avoid generic package names like
util
,common
,pkg
, etc.Keep import names lowercase, and the package name as the final part of the import path. Avoid stutter (
"code.google.com/p/goauth2/oauth2"
).The standard library is a good place to find good ways to write Go code, but not all of it is.
Effective Go: Names
Short, concise, and evocative.
Keep package names short, preferably one word.
The package name should be the basename of the directory it's in.
Don't prefix Getters with
Get
.Package Names (Go Blog)
Use short names (
time
,list
, andhttp
).Don't abbreviate if it causes ambiguity.
Avoid repition (stutter).
Use New as an entry point for client code.
The last element of the import path is the package name.
Meaningless (
util
,common
,pkg
) names are bad; they do not give any inidication of the package's contents.