golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.14k stars 17.69k forks source link

go/doc: enable grouping of functions with common names and suffix N #18858

Open mdlayher opened 7 years ago

mdlayher commented 7 years ago

Suggested by @griesemer in another proposal: https://github.com/golang/go/issues/18616#issuecomment-275761203.

An example of the proposed before and after output, for a series of functions called TrailingZeros with integer sizes "N" as a suffix:

Before:

// TrailingZeros16 returns the number of trailing zero bits in x.
// The result is 16 if x == 0.
func TrailingZeros16(x uint16) uint

// TrailingZeros32 returns the number of trailing zero bits in x.
// The result is 32 if x == 0.
func TrailingZeros32(x uint32) uint

// TrailingZeros64 returns the number of trailing zero bits in x.
// The result is 64 if x == 0.
func TrailingZeros64(x uint64) uint

After:

// TrailingZerosN returns the number of trailing zero bits in a uintN value x for N = 16, 32, 64.
// The result is N if x == 0.
func TrailingZeros16(x uint16) uint
func TrailingZeros32(x uint32) uint
func TrailingZeros64(x uint64) uint

Seems like a big usability improvement, and would be useful in at least sync/atomic as it exists now in the stdlib: https://golang.org/pkg/sync/atomic/. Would also be useful for some of the proposed APIs for a math/bits as discussed here: https://github.com/golang/go/issues/18616

jimmyfrasche commented 7 years ago

My questions/concerns are:

(as for modelling in go/doc the simplest way would just be to copy the doc string into each Func, but it would be hard to discover the grouping and the decl containing the actual comment without an additional field or method for retrieving the decl with the comment)

I'm not opposed to this change, and I could see it being a benefit, but I'm not convinced it justifies its complexity yet.

griesemer commented 7 years ago

@jimmyfrasche Some (possible) answers: