Ø  does it sounds good to disable (in specs) named return vars shadowing ?

 

This would help, but the := problem isn’t limited to return variables.  I think 
that it’s when there are two (or more) variables, and only one is new, that is 
the real flaw.  I would prefer that it only work when both variables are new.

 

I’ve taken to never using := in any multiple variable situation to avoid the 
problem.  This is something that a ver or lint utility can check for now, too.  
J

 

John

    John Souvestre - New Orleans LA

 

From: golang-nuts@googlegroups.com [mailto:golang-nuts@googlegroups.com] On 
Behalf Of djad...@gmail.com
Sent: 2017 February 22, Wed 09:35
To: golang-nuts
Cc: m...@renich.org
Subject: Re: [go-nuts] Re: Trying to understand := and named return values

 



On Wednesday, February 22, 2017 at 3:39:58 PM UTC+2, Marvin Renich wrote:

On Tue, Feb 21, 2017 at 1:46 PM,  <andrew.p...@gmail.com <javascript:> > 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. 

* Ian Lance Taylor [170221 16:13]: 
> Yes, named returns may have been a mistake.  Only use them in very 
> very short functions. 

* John Souvestre <jo...@souvestre.com <javascript:> > [170221 21:46]: 
> 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? 

I agree with the John and the others that named return variables are a 
good feature. 

The confusion is not because of the named returns, but because the := 
notation used with multiple variables on the left combines declaration 
and simple assignment without allowing, much less requiring, the 
programmer to explicitly identify which variables are being declared and 
which are simply being assigned a new value.  This is relevant when := 
is used at the block scope as well as in if/for/switch initializers. 

...Marvin 

 

 

 

does it sounds good to disable (in specs) named return vars shadowing ?

Djadala

 

-- 
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