Re: [go-nuts] some incorrect code in blog.

2021-11-27 Thread Brian Candler
Ergh. Thank you for putting me right. That is definitely a good reason for avoiding *named* return values completely. -- 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

Re: [go-nuts] some incorrect code in blog.

2021-11-27 Thread 'Axel Wagner' via golang-nuts
On Sat, Nov 27, 2021 at 11:03 AM Brian Candler wrote: > Whether (1) or (2) applies depends whether the final return is a "naked" > one or not. In this case it isn't: > > > *return io.Copy(dst, src)* > > Therefore, the value returned is whatever io.Copy() returns > That is not true

Re: [go-nuts] some incorrect code in blog.

2021-11-27 Thread Brian Candler
On Saturday, 27 November 2021 at 07:55:10 UTC tapi...@gmail.com wrote: > Isn't the code should be: > > *func CopyFile() {* > * ...* > * if err != nil {* > * return* > * }* > > * defer func() { err = src.Close() }()* > * ...* > *}* > No. Note that the signature of this function

Re: [go-nuts] some incorrect code in blog.

2021-11-26 Thread tapi...@gmail.com
Isn't the code should be: *func CopyFile() {* * ...* * if err != nil {* * return* * }* * defer func() { err = src.Close() }()* * ...* *}* On Thursday, November 25, 2021 at 12:18:20 PM UTC+8 Ian Lance Taylor wrote: > On Wed, Nov 24, 2021 at 6:14 PM Fannie Zhang wrote: > > > >

Re: [go-nuts] some incorrect code in blog.

2021-11-25 Thread Roland Müller
>>>> "os" >>>> ) >>>> >>>> func main() { >>>> f, err := os.Open("/tmp/dat") >>>> //defer f.Close() >>>> fmt.Printf("%v\n", f) >>>> if err != nil { >>>>

Re: [go-nuts] some incorrect code in blog.

2021-11-25 Thread David Karr
fmt.Printf("%v\n", f) >>> if err != nil { >>> fmt.Println("NO FILE") >>> //return >>>} >>>defer f.Close() >>>fmt.Println("END") >>> } >>> >>> Output: &

Re: [go-nuts] some incorrect code in blog.

2021-11-25 Thread Roland Müller
ntln("END") >> } >> >> Output: >> >> NO FILE >> END >> >> >> On 11/25/21 10:19, Fannie Zhang wrote: >> >> OK, I see. Thank you. >> >> >> >> *From:* Kurtis Rader >> *Sent:* Thursday, Novemb

Re: [go-nuts] some incorrect code in blog.

2021-11-25 Thread David Karr
> NO FILE > END > > > On 11/25/21 10:19, Fannie Zhang wrote: > > OK, I see. Thank you. > > > > *From:* Kurtis Rader > *Sent:* Thursday, November 25, 2021 10:26 AM > *To:* Fannie Zhang > *Cc:* golang-nuts > > *Subject:* Re: [go-nuts] so

Re: [go-nuts] some incorrect code in blog.

2021-11-25 Thread Roland Müller
Println("END") } Output: NO FILE END On 11/25/21 10:19, Fannie Zhang wrote: OK, I see. Thank you. *From:* Kurtis Rader *Sent:* Thursday, November 25, 2021 10:26 AM *To:* Fannie Zhang *Cc:* golang-nuts *Subject:* Re: [go-nuts] some incorrect code in blog. Notice the date of tha

RE: [go-nuts] some incorrect code in blog.

2021-11-25 Thread Fannie Zhang
OK, I see. Thank you. From: Kurtis Rader Sent: Thursday, November 25, 2021 10:26 AM To: Fannie Zhang Cc: golang-nuts Subject: Re: [go-nuts] some incorrect code in blog. Notice the date of that blog article: 2010-08-04. It's more than eleven years old. Blog articles are not updated

Re: [go-nuts] some incorrect code in blog.

2021-11-24 Thread David Karr
On Wed, Nov 24, 2021 at 6:14 PM Fannie Zhang wrote: > Hi all, > > There is some incorrect code in > https://go.dev/blog/defer-panic-and-recover blog. > > The original code is > *func CopyFile() {* > * ...* > * if err != nil {* > * return* > * }* > * defer src.Close()* > * ...* >

Re: [go-nuts] some incorrect code in blog.

2021-11-24 Thread Ian Lance Taylor
On Wed, Nov 24, 2021 at 6:14 PM Fannie Zhang wrote: > > There is some incorrect code in https://go.dev/blog/defer-panic-and-recover > blog. > > The original code is > func CopyFile() { >... >if err != nil { > return >} >defer src.Close() >... > } > > I think the correct

Re: [go-nuts] some incorrect code in blog.

2021-11-24 Thread Leam Hall
On 11/24/21 20:26, Kurtis Rader wrote: Notice the date of that blog article: 2010-08-04. It's more than eleven years old. Blog articles are not updated as the language changes. It might be good to resolve that. If the authoritative info source for the language makes a habit of keeping old

Re: [go-nuts] some incorrect code in blog.

2021-11-24 Thread Kurtis Rader
Notice the date of that blog article: 2010-08-04. It's more than eleven years old. Blog articles are not updated as the language changes. However, in this case the example in that article is correct. If `os.Open()` returns an error then the `src` return value is invalid. On Wed, Nov 24, 2021 at

[go-nuts] some incorrect code in blog.

2021-11-24 Thread Fannie Zhang
Hi all, There is some incorrect code in https://go.dev/blog/defer-panic-and-recover blog. The original code is *func CopyFile() {* * ...* * if err != nil {* * return* * }* * defer src.Close()* * ...* *}* I think the correct code should be *func CopyFile() {* * ...* * defer