News for hackers. Stuff that matters.
Re:Goro – An implementation of PHP written in Go by nkozyra on Monday November 26, 2018 @07:21PM (#18538116)
Probably the repetition of

if err != nil {}

You get used to that pretty quickly in Go, but it still looks messy to a lot of people.

Re:Goro – An implementation of PHP written in Go by dymk on Monday November 26, 2018 @08:00PM (#18538363)
And so it's clear to others, this probably the worst possible way for a language to go about implementing error handling (maybe aside from just not having any mechanism outright and terminating).

But alas, those are the choices that the Go language made.

Re:Goro – An implementation of PHP written in Go by isodude on Monday November 26, 2018 @08:17PM (#18538470)
Is it really though? I've tried out Exceptions in most languages and Go's error handling stuck out to me as the first one that is clear what it does, which of course is the mantra of the language.
Re:Goro – An implementation of PHP written in Go by TheDong on Monday November 26, 2018 @08:26PM (#18538522)
Exceptions are a strawman.

Compare it to another modern language such as rust. Go does not have a stdlib mechanism for converting error types into each other (akin to rust's Into), it doesn't have the idea of mapping values together (akin to rust's carrier operator which is basically like monad do syntax), it doesn't have a way to create a list of errors by default (akin to 'cause' in rust), it doesn't have a way to generate concrete error types for your functions (like the 'failures' or 'error-chain' libraries in rust, which can't be written in go due to a lack of macros and generics and sum types).

It doesn't have a way to match on all possible concrete error values (akin to 'match' in rust or other sum-type things) or to do thing slike '.and_then' or '.map_err' or so on.

Go's error handling is downright insulting in a language that wasn't built at the same time as c.

Re:Goro – An implementation of PHP written in Go by bouncycastle on Monday November 26, 2018 @08:27PM (#18538524)
The alternative is just as bad, a multi block try and catch mess that is in Java!
Re:Goro – An implementation of PHP written in Go by wild_preference on Monday November 26, 2018 @08:34PM (#18538559)
No, the alternative here would be to just let the write()'s throw and let upstream handle them. You don't try/catch to catch an error just to re-throw it for the same reason you don't try/catch every single line of your program.

Exceptions are one reason other languages don't need this "if err throw err" code, without making a comment on if either is superior.

Re:Goro – An implementation of PHP written in Go by bouncycastle on Monday November 26, 2018 @09:13PM (#18538746)
Yeah, but an error error is not really an exception. Often in Go, errors are used to mark different states, such as EOF which are expected and you can deal with locally and have more control whenever you want to return or not, for example, you can test the error in the same if condition and decide whenever to keep going - usually you do. Error handling code is more local rather than all over the place, plus no need to declare more classes for specific exceptions.
Re:Goro – An implementation of PHP written in Go by dymk on Monday November 26, 2018 @11:58PM (#18539520)
> Often in Go, errors are used to mark different states, such as EOF which are expected

Then it's not an error, and Go has once again forced people into writing something semantically confusing and/or incorrect because it lacks basic abstractions.

Re:Goro – An implementation of PHP written in Go by bouncycastle on Tuesday November 27, 2018 @02:34AM (#18540288)
Actually, any type can be an error, just as long as it impliments the Error interface. Go is more about interfaces - if some type impliments some interface, then that's what it is.