On Thu, Oct 13, 2016 at 8:36 AM,  <d...@veryhaha.com> wrote:
> On Thursday, October 13, 2016 at 11:24:50 PM UTC+8, Jesper Louis Andersen
> wrote:
>> The rule is that a short variable declaration requires that at least one
>> non-blank variable is new (the specification even says so) Consider
>>     _, y := 4,5
>> where one variable, y, is new. In
>>     _ := 6
>> or
>>     _, _ := 5, 7
>> this rule is violated, since there are no non-blank variables (and thus
>> vacuously nothing new).
>> I think the reason this is a rule is because it may detect some spurious
>> errors by forcing the programmer to write code in a certain style, but I may
>> be wrong.
> What spurious errors?

The error of thinking that because you are using := you are getting a
new variable.

The handling of := is a bit tricky, perhaps too tricky.  It used to
always declare new variables, and give an error if there was already a
variable of the same name in the same scope.  But that was too painful
to use with the err variable, because of the common use of
    n, err := F()
So := was changed to permit reusing a variable if it already existed
in the same scope with the same name and (inferred) type.


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