Function parameters are not a good place (in general - there are
exceptions) to document arguments.

// Frob the outer otter.
FrobOuterOtter(otter Otter)

is not better than

// Frob the outer otter
FrobOuterOtter(Otter)

from the standpoint of external documentation.

But if you want the function to have access to the parameters, you need to
name them. The same is not true for return values.

// Add two numbers
Add(x, y int) int

is fine. This is silly:

// Add two numbers
Add(x, y int) (sum int)

Since the comment already says in English what is returned, there isn't any
value to repeating it again in the return value. *Except *when there are
multiple ones and the order matters:

// Lookup returns the name and email address of the user.
Lookup(id Identity) (name, email string)


On Tue, Feb 21, 2017 at 6:46 PM John Souvestre <j...@souvestre.com> wrote:

> I feel the opposite.  I view named returns as documentation of a
> function's parameters.  I'm constantly amazed by the (correct) emphasis
> placed on using appropriate names for calling parameters, but not for the
> return parameters.  The goal is that I shouldn't have to read a function's
> code to use the function, right?
>
> So how can the disparity be justified?  Oh, and the longer the function is
> the more benefit there is to using them.
>
> John
>
>     John Souvestre - New Orleans LA
>
>
> -----Original Message-----
> From: golang-nuts@googlegroups.com [mailto:golang-nuts@googlegroups.com]
> On Behalf Of Ian Lance Taylor
> Sent: 2017 February 21, Tue 16:13
> To: andrew.penneba...@gmail.com
> Cc: golang-nuts
> Subject: Re: [go-nuts] Re: Trying to understand := and named return values
>
> On Tue, Feb 21, 2017 at 1:46 PM,  <andrew.penneba...@gmail.com> wrote:
> > Seems like named returns + if/for/switch initializers = a shadowing
> > nightmare. I wish the Go compiler emitted a loud warning on shadowing, as
> > this is a dangerously subtle problem out there.
>
> Yes, named returns may have been a mistake.  Only use them in very
> very short functions.
>
> Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to