News for hackers. Stuff that matters.
Re:The Next Step for Generics by fooster on Tuesday June 16, 2020 @06:06PM (#23544866)
Error handling is hard, period. Error handling in go is no worse than any other language, and in most ways it is better being explicit and non-magic.

> people who designed it did not have a proper language design background

Irrelevant.

> It's just bad language design.

try { ... } catch(Exception ex) { ... }

Re:The Next Step for Generics by entha_saava on Wednesday June 17, 2020 @12:06AM (#23547657)
Exceptions don't lead to silent but dangerous and hard to debug errors. The program fails if exception is not handled.
Re:The Next Step for Generics by apta on Tuesday June 16, 2020 @09:03PM (#23546452)
> try { ... } catch(Exception ex) { ... }

The error here is explicitly handled, and cannot be accidentally ignored. Unlike golang where it's quite easy for errors to go ignored accidentally.

Re:The Next Step for Generics by fooster on Tuesday June 16, 2020 @09:42PM (#23546751)
Nevertheless, this is how it is mostly done in Java. I haven't used eclipse in eons, but last time I did it even generated this code.

If you care with go, use errcheck.

Re:The Next Step for Generics by apta on Wednesday June 17, 2020 @12:02AM (#23547631)
Does errcheck work well with gorm (https://gorm.io/) and it's way of returning errors? This is not an obscure library, it's quite widely used.
Re:The Next Step for Generics by ori_b on Wednesday June 17, 2020 @12:24AM (#23547771)
Does any language save you from explicitly screwing up error handling? Gorm is doing the Go equivalent of:

     class Query {
         class QueryResult {
             Exception error;
             Value result;
         }
         public QueryResult query() {
             try {
                 return doThing();
             } catch(Exception e){
                 return new QueryResult(error, null);
             }
         }
     }
Gorm is going out of its way to make error handling suck.
Re:The Next Step for Generics by apta on Wednesday June 17, 2020 @03:46PM (#23555856)
> Does any language save you from explicitly screwing up error handling?

It's about the default error handling method being sane. In exception based languages, an unhandled error bubbles up until it reaches a handler, or it crashes the program with a stacktrace.

Compare to what golang does, it's somewhat easy to accidentally ignore or overwrite errors. This leads to silent corruption of state, much worse than crashing the program outright.

Re:The Next Step for Generics by ori_b on Wednesday June 17, 2020 @05:14PM (#23556859)
> It's about the default error handling method being sane.

Gorm isn't using the default error handling.

Re:The Next Step for Generics by apta on Wednesday June 17, 2020 @07:21PM (#23558019)
That's one point in this discussion. The language allows error handling that way. Compared to a language with proper sum types or exceptions, where one would have to actively work against the language to end up with that mess.
Re:The Next Step for Generics by ori_b on Wednesday June 17, 2020 @08:26PM (#23558471)
> That's one point in this discussion. The language allows error handling that way. Compared to a language with proper sum types or exceptions, where one would have to actively work against the language to end up with that mess.

I've seen a bunch of code that does the equivalent of the Java I posted above. Mostly when sending errors across the network.

Re:The Next Step for Generics by hactually on Tuesday June 16, 2020 @09:11PM (#23546512)
because it has try/catch. Without that (which would be similar to not checking the err in go) it explodes or throws to a layer up that may not expect it.

Each language has its wonks.

Re:The Next Step for Generics by apta on Tuesday June 16, 2020 @11:53PM (#23547572)
> Without that (which would be similar to not checking the err in go) it explodes or throws to a layer up that may not expect it.

It's not similar to that at all. Without it, the exception bubbles up until it gets caught somewhere, or crashes the program with a useful stacktrace.

With golang, it just goes undetected, and the code keeps running with corrupt state, without anyone knowing any better.