Effective Go Summary

Martin Sidorov
9 min readSep 11, 2024
Photo by Austin Distel on Unsplash

I have read Effective Go and distilled the key points into a summary. This will allow everyone to quickly grasp the essential effectiveness tips and practices. Here we go:

Package Names

When importing a package in Go, the package name becomes the access point for its contents. It’s recommended to use short, concise, and descriptive names to facilitate ease of use. Package names are typically lowercase and single-word to minimize typing. If there’s a naming collision, you can locally rename imported packages to avoid conflicts. Package names derive from the base name of their source directory, like “encoding/base64” imported as “base64.”

Example:

import (
"fmt"
b64 "encoding/base64" // Renaming for clarity
)

func main() {
encoded := b64.StdEncoding.EncodeToString([]byte("hello, world!"))
fmt.Println(encoded)
}

MixedCaps

Go conventionally uses MixedCaps (also known as camelCase) for multi-word names, rather than underscores. This style ensures consistency and readability across the language.

Example:

var myVariable int
var anotherLongVariableName string
func myFunctionName() {
// Function body
}

Getters and Setters

  • If you have a field named `owner`…

--

--

Martin Sidorov
Martin Sidorov

Written by Martin Sidorov

A passionate Software Engineer from Estonia

No responses yet