Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a timely article because I was just talking to a friend of mine that works at Google and is about to start an internal project that will be written in Go.

I told him I'm not sure I'd ever fit into the Go community because the Go community seems to like variable names that are extremely short. For example:

  func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
I've even been "gently corrected" in #go-nuts on Freenode when I've shared code and I used "res" instead of "w" and "req" instead of "r" -- they told me my longer variable names wasted space and made it harder to read.

Perhaps my brain works different, but I find variable names that are actual words much easier to read.



The thing about the arguments to an http.HandlerFunc is that everyone uses w and r for the argument names because everyone else does. Additionally, if you're writing a http.HandlerFunc, you're likely repeatedly exposed to a bunch of other http.HandlerFuncs in standard library code and gorilla/mux, all of which use w and r.

Because of this, anyone who's been wrangling HandlerFuncs for more than a few days tends to converge on w and r. At this point it's no more a problem than using short variables like d for distance or r for radius in math formulas.

As an aside, I have a file open right now with a struct member called "TentativeSpacesPerIndent int"; I'm not worried — yet — about how ungainly long it is because I'm still trying to figure out what indices I need to keep track of, and the last thing I want to do is confuse myself into using one type of index when I need another, or perhaps I need to track of something else entirely. On the other hand, I have

  func NewScanner(bs []byte) Scanner
and all the thought I put into the name of the argument is "if a single byte should be a 'b', what should a slice of bytes be? 'bs'." That seems to be sufficient length for a five-line function.


These are the same individuals that will argue with you until the end of time about how generics are never necessary and carry too much cognitive burden.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: