Uninteresting parts of Effective Go
Here are some uninteresting parts of Effective Go. Effective Go is a little tour of the Go programming language. Go is an okay language I guess.
Appending a slice to a slice
// Use ...
x := []int{1,2,3}
y := []int{4,5,6}
x = append(x, y...)
Short declaration re-assignments
“Err appears in both statements. This duplication is legal: err is declared by the first statement, but only re-assigned in the second.”
// This is okay
fp, err := os.Open(fName)
d, err := fp.Stat()
Defer
“It is an effective way to deal with situations such as resources that must be released regardless of which path a function takes to return.”
Getters and setters
“It’s neither idiomatic nor necessary to put Get into the getter’s name.”
// This is correct
prop := foo.Property()
// Don't do this
prop := foo.GetProperty()
The new keyword
“Beginners are confused by the distinction between the allocation routines make and new.” In fact, this post by Rob Pike describes how new was almost removed.
v := new(int)
*v++
fmt.Println(*v)
Written on April 20, 2021