Go helps with that. Even team's proposal was finally retracted:
https://github.com/golang/go/issues/32437 Discussion there is lengthy, but worth
reading to sense why wider community considers "boilerplate" as asset.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d9cdb32d-2609-4ae9-a9ff-36830c877245n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/32657f71-d9c1-4a79-9528-ad6a73af954cn%40googlegroups.com.
Go - whether people like this or not - is VERY close to Java (because of the “runtime”) - and both suffer from “runtime overhead/startup cost”
OT, but what has happened to the Go 2 error handling proposals?
I heard that the original check proposal was abandoned because of the
unfortunate interaction with defer.
Any updates?
On Feb 18, 2021, at 5:13 AM, 'Carla Pfaff' via golang-nuts <golan...@googlegroups.com> wrote:
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c60af668-55d6-4977-a746-b04dbc67e31an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1c510a2c-981b-4980-8f47-7a025769e233n%40googlegroups.com.
Rust lang, very early in its evolution, saw the need to create its operator '?' to more efficiently manage error handling. But the guardians of Go lang have resisted any changes to its clumsy method of error handling despite it being a major concern of Go users for a very long time.
On Sunday, February 14, 2021 at 11:14:11 AM UTC-5 ohir wrote:Dnia 2021-02-13, o godz. 17:44:47
Michael MacInnis <michael.p...@gmail.com> napisał(a):
> I've been playing around with reducing error handling boilerplate
You're not alone. Hundreds of us went into such thinking in the first weeks
of reading/using Go - yet before we noticed how much more productive we
are with Go's "boilerplate" than we were in languages where handling errors
(failures) was "a problem of others", including future-us as "others".
Perceived consensus of the Go community is that "error handling boilerplate"
is a strong feature. I.e. in normal production software you MUST handle failures
and you should do it as close as possible to the source of said failure.
Go helps with that. Even team's proposal was finally retracted:
https://github.com/golang/go/issues/32437 Discussion there is lengthy, but worth
reading to sense why wider community considers "boilerplate" as asset.
Error handling proposals umbrella: https://github.com/golang/go/issues/40432
> Michael.
Hope this helps,
--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/2b2b2ecc-18e6-4e4c-b71c-581d6ff0fc16n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgacim5uPaik2_QxgafB5uZ589ojWmbFdy54U6etHn4x5z0g%40mail.gmail.com.
On Feb 20, 2021, at 1:39 PM, Matthew Holiday <matthew...@nytimes.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGSa1C%3DyS48YXZ95ut_LaEiBU2MKCKF5pERgkW5q7%2BHVFv4Stw%40mail.gmail.com.
On Feb 20, 2021, at 2:31 PM, Matthew Holiday <matthew...@nytimes.com> wrote:
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGSa1Cnc_%2BXFRE%3DKW6J%3DPUc39UGF4aD%2BBCSBpnHVF2i0Ceg22Q%40mail.gmail.com.
On Feb 21, 2021, at 8:51 PM, Ian Davis <m...@iandavis.com> wrote:On Sun, 21 Feb 2021, at 5:23 PM, robert engels wrote:Can someone please explain the benefit of ‘error return’ over ‘checked
exceptions’ ? I have made the point a few times and it goes to crickets
- I have to believe that is because there is none, or it is difficult
to communicate.
I think since this is a Go list, the onus is on advocates of exceptions to demonstrate the benefit of checked exceptions over error return values.
Here are a couple of scenarios that I encountered recently that had logical linear flow with error returns. I'm curious how they would be improved with checked exceptions:
1) open three files for writing, closing the earlier ones if a subsequent one fails to open
public static void writeFiles() throws IOException {
try(FileOutputStream f1 = new FileOutputStream("file1");
FileOutputStream f2 = new FileOutputStream("file2");
FileOutputStream f3 = new FileOutputStream("file3")
) {
// at this point all files are open for writing and ready to be processed
// if any open failed, the other files are closed
}
}
2) open a file for append, falling back to creating a new writeable file if the original is read-only or doesn't exist. The new file creation may also fail due to disk errors or permissions.
public static void openFile() throws IOException {
try(FileOutputStream f1 = new FileOutputStream("somefile",true);
) {
// at this the file is open for writing and will be closed when the block/method exits
}
}
class Test {
private static FileOutputStream openAppendOrCreate(String name) throws FileNotFoundException {
try {
return new FileOutputStream(name,true);
} catch(FileNotFoundException e){
return new FileOutputStream(name);
}
}
public static void openFile() throws IOException {
try(FileOutputStream f1 = openAppendOrCreate("somefile");
) {
// at this the file is open for writing and will be closed when the block exits
}
}
}
I can envisage how to write them with exceptions but I'm struggling to see where it would be more succinct or easier to read.
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9f3cf023-5bb4-49da-a842-0be97904d21a%40www.fastmail.com.
On Feb 23, 2021, at 6:03 AM, Nigel Tao <nige...@golang.org> wrote:
If you're proposing exceptions, be aware of how complicated the control flow for correct handling can be. Look for what follows `The statement "RESULT = yield from EXPR" is semantically equivalent to...` in https://www.python.org/dev/peps/pep-0380/
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOeFMNUEOGf1r-1FpCTFJ0ze9s26ZNqN9vGLGVDoCcaW72%2B9ag%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/155bf359-2cd3-4d2a-8966-f92d8488426cn%40googlegroups.com.
I realize that this thread ended up diverging into a wider discussion of exceptions and error handling in general but I wanted mention one of the problems I discovered and maybe a potential solution for others who may be tempted to play around with something like this.I originally thought that one of bigger problems with (ab)using panic and recover for control flow and trying to wrap this up in a package would be forgetting to defer the function performing the recover. As mentioned previously I think it's possible to structure things so that it is harder to make this mistake and I think a linter could also be written to catch these cases.But I think the bigger problem is the function that panics being used after the function with the deferred recover exits or in a different goroutine.It looks like the Go compiler's escape analysis can be used to detect this though. At least currently. With an inline definition of check and a deferred recover that looks like this:var check func(error){pnc := falsecheck = func(ce error) { // watch for "func literal escapes to heap"if ce != nil {err = ce// Only panic if we haven't previously.if !pnc {pnc = truepanic("escaping")}}}defer func() {if pnc {_ = recover()}}()}// Code that uses check.When compiled with `go build -gcflags -m` if the Go compiler says that the func literal assigned to check escapes to the heap there's a good chance it is being used in a way that won't end well. It even catches uses like this:c := make(chan struct{})go func() {check(nil)close(c)}()<-cwhere check doesn't out live the function with the deferred recover but it is being used in a different goroutine. So, at least currently, it looks like the compiler can be used to check for unsafe uses of a function like this.What I'm wondering is are there cases that the compiler won't catch and is this likely to stop working in some future release where, in a block of code like the one above, the compiler will decide that the function doesn't need to escape to the heap?Michael.