top | item 43314206

(no title)

stevebmark | 11 months ago

Idiomatic Go is using shortened variable names, not what's in this article. I thought that was common knowledge and part of the Go ethos? I also wouldn't consider grammar in comments part of the language idioms? This is an unusual and very light take on Golang language idioms.

discuss

order

prisenco|11 months ago

My understanding is that shortened variable names are recommended for small, tight contexts (loops, short functions) but not generally.

cube2222|11 months ago

That and conventionally standard names, like r for request/reader, w for writer, etc.

Agreed. Functions shouldn’t be full of short non-descriptly named variables.

The longer the lifetime/scope of a variable, and the more variables there are, the more descriptive the names should be.

GauntletWizard|11 months ago

These are dang short compared to Java's FooBarBazBeanFactoryFuncClassImpl. The point you may be responding to is that "Short variable names" are themselves contextual. If you're doing a simple loop:

  for i := range personlist {
    person := personlist[i]
    ...
  }
Is more readable than

  for personNum := range personlist {
    person := personlist[personNum]
    ...
  }
because it makes clear that the i is basically irrelevant. The latter isn't bad style if you're three loops deep, because i, j, k is a bit harder to keep track of which is which.