On Mon, Dec 28, 2020 at 11:40 AM bobj...@gmail.com <bobja...@gmail.com> wrote: > > For the case of multiple variable assignment where some of the target > variables are to be created in the local scope and some are to be found in > the existing scope... > > Allow: > > existingVar, :newVar = 1, 2 > > instead of: > > var newVar int > existingVar, newVar = 1, 2 > > That additional line for explicit local var declaration clutters the program > and could even be a bit confusing. > > With this suggestion, current syntax and semantics of multiple assignment > stay the same. Use of the more concise syntax is optional, of course. > > Advantages: > - More readable > - More concise > - Easier to understand at a glance -- current rules are a tad complex and > require knowledge of previously-declared variables in the current block > - Does not break existing programs > - I look at this as "factoring out" the colon :) > > Disadvantages: > - Can't think of any > > For me, the most common use case is where the first variable exists outside > of the enclosing block and the second is an error to be handled locally: > > var err error > loopCount, err = strconv.Atoi(arg) > if err != nil { > ... > > Always bothers me to have to insert that "err" declaration. To me, this seems > much nicer: > > loopCount, :err = strconv.Atoi(arg) > if err != nil { > ... > > I think the above is a worthwhile improvement and should be considered. > > Thoughts?
There is a fair amount of discussion about this and other possible approaches at https://golang.org/issue/377. 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVjucHT-cY1UoNXVE2u6L0CQGCzD8bno82-DZ0i7sddgg%40mail.gmail.com.