What is the convention for lines of code with comments?

Go Model Code Formatting Agreement: " gofmtis an agreement." There is one part of this agreement that is hard for me to understand, and it would be great to have a formal definition of what gofmtis implementation, rather than the need to derive a model from empirical examples. Here is a sample.

To go fmt:

func sieve(mine int,                  // This instance 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 prime

After go fmt:

func sieve(mine int, // This instance 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 prime

Can someone help me understand what is going on here? This is why some comments were compressed to the detriment, while others were expanded? Some theories:

  • It's so ugly that it should mean that code without comments on one line is preferable
  • There is a mistake in gofmt
  • Incomplete (in some way) lines are processed differently than full
  • Something else?
+5
1

/. math/big.(*Int).Exp docs:

// Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
// If y <= 0, the result is 1 mod |m|; if m == nil or m == 0, z = x**y.
// See Knuth, volume 2, section 4.6.3.
func (z *Int) Exp(x, y, m *Int) *Int {

, x, y m . , godoc.

, :

// First-number switch.
start := true
// Output channel, this instance.
ouch := make(chan int)
// Print this instance prime.
fmt.Printf("%v ", mine)
+6

Source: https://habr.com/ru/post/1627294/


All Articles