[go-nuts] Re: about "hybrid barrier"

2023-07-30 Thread 'Michael Knyszek' via golang-nuts
On Friday, July 28, 2023 at 8:05:03 AM UTC-4 metronome wrote: Hi, I came across two questions regarding the hybrid barrier that I am hoping someone can help with. 1. Chang https://go-review.googlesource.com/c/go/+/31765 says: *"It's unconditional for now because barriers on channel

[go-nuts] Re: Error handling

2023-07-30 Thread Marcello H
I think the current error handling is just fine. For the extra typing, they invented keyboard snippets and such. But for this proposal, I would like to see how a return with multiple values would look to get a better understanding. ``` // translate this in the proposed solution? func

[go-nuts] Function defitions using F12 in visual studio code

2023-07-30 Thread nutzeeer
Hi, Using F12 in visual studio code does not find any defintions for the go code. Go and the visual studio code extenstion are installed. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails

[go-nuts] Re: Error handling

2023-07-30 Thread Jeremy French
Also, errors are values, which means - although uncommon - a function could return two or more error values. Which would orelse evaluate? Even if you arbitrarily chose one, that would violate the explicit vs implicit code flow principle. My sympathies, OP. I too hate the "if err!= nil"

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
err := io.Copy(w, r) *orelse* { w.Close() os.Remove(dst) return fmt.Errorf("copy %s %s: %v", src, dst, err) } My question still stands. Semantically, what value exactly does the "orelse" condition test is not equal to nil? - does it test the value from the preceding assignment? If so, is

Re: [go-nuts] Re: Types like http.Request and slog.LogValuer

2023-07-30 Thread 'Jonathan Amsterdam' via golang-nuts
Another idea: write a handler that wraps whatever handler you usually use. That handler looks through the Record for attr values of type *http.Request, and replaces them with whatever formatting you want. You might even be able to do that with a ReplaceAttr function with the built-in handlers. On

[go-nuts] Re: Error handling

2023-07-30 Thread DrGo
Good point Harri, This is what the correct version will look like using this proposal func CopyFile(src, dst string) error { r, err := os.Open(src) *orelse* return fmt.Errorf("copy %s %s: %v", src, dst, err) defer r.Close() w, err := os.Create(dst); *orelse* return fmt.Errorf("copy %s %s:

[go-nuts] Re: Error handling

2023-07-30 Thread DrGo
Apologies if I am not understanding your question, but does not the compiler know the types of all variables (including the returned variables)? The compiler will emit code to execute the orelse block if the error variable (regardless of its name or concrete type) in the preceding statement is

[go-nuts] Re: Error handling

2023-07-30 Thread Harri L
IMHO, you have used the irrelevant example (== 2nd code block) from Russ Cox's paper. The paper says: > This code is not nice, not clean, not elegant, *and still wrong:* like the previous version, it does not remove dst when io.Copy or w.Close fails. I want to compare your proposal with the

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
Typo: should have said var foo error r, bar := os.Open(src) orelse return foo // does this do "if foo != nil { return foo }" ?? On Sunday, 30 July 2023 at 10:20:12 UTC+1 Brian Candler wrote: > On Sunday, 30 July 2023 at 09:40:25 UTC+1 DrGo wrote: > > orelse must return an error (ie satisfies

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
On Sunday, 30 July 2023 at 09:40:25 UTC+1 DrGo wrote: orelse must return an error (ie satisfies the error interface); the specific type and variable name do not matter. But how does "orelse" perform the check in the first place? Does it look for the variable named in the return statement?

[go-nuts] Re: Error handling

2023-07-30 Thread DrGo
thanks for the link. unlike the onErr approach, my proposal does not treat create special-status identifier; the orelse block is like any other else block On Sunday, July 30, 2023 at 1:31:09 AM UTC-6 Brian Candler wrote: On Sunday, 30 July 2023 at 06:57:15 UTC+1 DrGo wrote: I looked at the

[go-nuts] Re: Error handling

2023-07-30 Thread DrGo
orelse must return an error (ie satisfies the error interface); the specific type and variable name do not matter. although on second thought.. I am not sure that even that restriction is necessary. On Sunday, July 30, 2023 at 1:02:04 AM UTC-6 Brian Candler wrote: Just to be clear: are you

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
On Sunday, 30 July 2023 at 06:57:15 UTC+1 DrGo wrote: I looked at the long list of proposals to improve error handling in go but I have not seen the one I am describing below. There is a meta-ticket here: https://github.com/golang/go/issues/40432 Under the section "Simplifications of if err

[go-nuts] Re: Error handling

2023-07-30 Thread Brian Candler
Just to be clear: are you hard-coding the variable name "err" into the semantics of "orelse"? That is, you can't assign the error return to a variable of any other name? I disagree that this makes the job of linters any easier than it is today. For example, if you'd written ...