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
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
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
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:
> >
> >
>>>> "os"
>>>> )
>>>>
>>>> func main() {
>>>> f, err := os.Open("/tmp/dat")
>>>> //defer f.Close()
>>>> fmt.Printf("%v\n", f)
>>>> if err != nil {
>>>>
fmt.Printf("%v\n", f)
>>> if err != nil {
>>> fmt.Println("NO FILE")
>>> //return
>>>}
>>>defer f.Close()
>>>fmt.Println("END")
>>> }
>>>
>>> Output:
&
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
> 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
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
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
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()*
> * ...*
>
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
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
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
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
15 matches
Mail list logo