[Golang] Housekeeping

[Golang] Housekeeping

Golang 中當你 import 套件進來,卻沒使用會噴錯誤

還有當你宣告變數,卻沒使用也會噴錯誤

這兩點很得我心,co-work最討厭遇到沒用到變數、套件一堆,卻又不好刪. . .

idiomatic go: write clear, simple, readable code => 理想中的Go是乾淨、簡單、可獨得

Golang is all about the type

You need write enough but not too much. 使用struct的時候,要記得把key也寫上去

func main() {
	p1 := struct {
		first string
		last  string
		age   int
	}{
		first: "James",
		last:  "Bond",
		age:   32,
	}
	fmt.Println(p1)
}

這一段程式,跟下面執行結果一樣,但是你要寫清楚的程式

func main() {
	p1 := struct {
		first string
		last  string
		age   int
	}{
		"James",
		"Bond",
		32,
	}
	fmt.Println(p1)
}

...