I watched a talk given by Brian Ketelsen, where he suggested to use repeated letters to represent a slice.
For instance:
var tt []*Thing
I am not sure whether it is a great idea. In my case, I am writing an http handler
that fetches URL param “message”. So, my code looks like this:
func handlePut(w http.ResponseWriter, r *http.Request) {
mm, ok := r.URL.Query()["message"]
if !ok || len(mm) != 1 {
http.Error(w, "", http.StatusBadRequest)
return
}
m := mm[0]
...
I don’t feel like this naming is a right thing to do. I guess that is would be more readable if I used messages and message names instead. Could anyone give me an advice here?
Just by taking a look at a random file in golang/go source tree, lookup.go, it seems there are many places they use -s suffix. Usually when I see a tt identifier it is identifying a test table.
I second what olavfosse said; an s suffix makes more sense to me than doubling the character. I think in Spanish, it’s not uncommon to double characters to signify plural (e.g. I think Estados Unidos (“United States”) becomes “EEUU”).
I also like your idea of just saying messages. It’s idiomatic in Go to use short variable names and I personally follow that guideline, too, but only for small functions that fit in a single “screenful” and where there are few variables in the whole function.