The Go model of code formatting conventions is "gofmt
is the convention". There is one part of that convention I'm having difficulty in understanding, and it would be great to have a formal definition of which gofmt
is an implementation, rather than having to deduce the model from empirical examples. Here's a sample.
Before go fmt
:
func sieve(mine int, // This instance's own prime
inch chan int, // Input channel from lower primes
done chan int, // Channel for signalling shutdown
count int) { // Number of primes - counter
start := true // First-number switch
ouch := make(chan int) // Output channel, this instance
fmt.Printf("%v ", mine) // Print this instance's prime
After go fmt
:
func sieve(mine int, // This instance's own prime
inch chan int, // Input channel from lower primes
done chan int, // Channel for signalling shutdown
count int) { // Number of primes - counter
start := true // First-number switch
ouch := make(chan int) // Output channel, this instance
fmt.Printf("%v ", mine) // Print this instance's prime
Can anyone help me understand what's going on here? That is, why have some comments been detrimentally compressed, and others expanded? Some theories:
- This is so ugly it must mean that code without comments on the same line is preferred
- There's a bug in
gofmt
- Incomplete (in some way) lines are treated differently from complete one
- Something else?
package
, type and func declarations will show up in godoc. For license headers, leave a blank line between the header and the package godoc comment. – Lubeck