Skip to content

proposal: x/pkgsite, go/doc: un-name result parameters starting with an underscore in docs #69867

Open
@bradfitz

Description

@bradfitz

Using a defer func to read/modify a function's results is convenient, except that it requires that you name the results, often unnecessarily, violating the style norms as documented at https://go.dev/wiki/CodeReviewComments#named-result-parameters, adding distracting repetition.

I was complaining about this with @ianlancetaylor @griesemer et al, and me saying how I wished there was a way to reference result parameters without naming them.

It was then counter-proposed that instead of changing the language, we could just change the pkgsite/godoc text+HTML-ifier to hide the named results based on a heuristic, such as names starting with an underscore.

Concretely, the proposal is that functions like:

func ExportedFoo(x int) (_node *Node, _err error) { ... }
func ExportedBar() (_err error) { ... }

... be instead rendered in godoc (either plaintext or HTML) as:

func ExportedFoo(x int) (*Node, error) { ... }
func ExportedBar() error { ... }

The alternative is either putting up with ugly docs, or writing this boilerplate:

func ExportedFoo(x int) (*Node, error) {
    return actualFoo(x)
}

func actualFoo(x int) (node *Node, err error) { ... }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions