News for hackers. Stuff that matters.
Re:A minimal blog engine written in Go, compatible with Ghos... by vardump on Saturday April 25, 2015 @07:10PM (#9439860)
Explicit error recovery is not hell, it's a blessing. Much easier to understand and to maintain than exception handling.
Re:A minimal blog engine written in Go, compatible with Ghos... by tomjakubowski on Saturday April 25, 2015 @07:49PM (#9439948)
There is a third way. See Haskell's Either l r, or Rust's Result<T, E> types. See http://lucumr.pocoo.org/2014/10/16/on-error-handling/ and http://lucumr.pocoo.org/2014/11/6/error-handling-in-rust/

I don't know why so often, the immediate reaction to legitimate criticism of this wart in Go is to argue against exceptions, even when nobody has even brought up exceptions as an alternative.

Re:A minimal blog engine written in Go, compatible with Ghos... by thirsteh on Saturday April 25, 2015 @08:20PM (#9440031)
In fact, Either/Maybe can function like safer versions of both paradigms: Functors allow you to build a program of many functions that will terminate with 'Nothing' or 'Either l' as long as any one of them experiences an error, without thinking about errors, and it still lets you explicitly handle any errors if you want to, this time on the sum type Maybe or Either, meaning that you usually handle both the error and non-error case, or receive a compiler warning.

I agree that, probably universally, the people who fervently argue for either exceptions or explicit Go-style error handling don't know about Maybe/Either/Result. Then again, all this is pretty much impossible to replicate in Go.

Re:A minimal blog engine written in Go, compatible with Ghos... by Dewie2 on Sunday April 26, 2015 @12:01PM (#9442152)
Thank you for mentioning this. It's frustrating that every time someone complains about Go's error-handling style, the first assumption is that the complainer then necessarily has to prefer exceptions. In truth, errors-as-values are very elegant in languages like Haskell IMO. And errors-as-values are not at all something that Go has managed to put back on the roadmap in a modern language against the grain of everyone else (the "exception people") as many seem to imply, including Rob Pike in his "errors as values" article.
Re:A minimal blog engine written in Go, compatible with Ghos... by vezzy-fnord on Saturday April 25, 2015 @08:26PM (#9440044)
Option types are nice. The fourth way (and I think the best) is supervision trees, though this is more applicable when you have multiple units of execution... which Go does, so not having something similar out of the box seems strange.

That said, even something as simple as errors being literal values that you can pattern match on is surprisingly versatile. Exceptions don't necessarily have to be awful weights that spill down all over the call stack, either. They can be distilled to a more basic catch/throw mechanism for shuffling around error properties and states.

Re:A minimal blog engine written in Go, compatible with Ghos... by threeseed on Saturday April 25, 2015 @08:46PM (#9440082)
Personally I love option types but working on a large Scala project at the moment it sometimes results in non ideal behaviour from developers especially those coming from the Java world.

What I've seen a lot of is swallowing of errors. For example readFromFile().orElse("") where there is no indication from an outsider that anything wrong happened. A cool feature would be logging any instance of when orElse was the result.

Would be curious how these work in other languages.

Re:A minimal blog engine written in Go, compatible with Ghos... by Jweb_Guru on Sunday April 26, 2015 @12:54PM (#9442353)
The trick is to make it very ergonomic to return the error. I thought Scala had do notation to make this the case. In Rust, the try! macro (which returns on error) is shorter than almost any other way to handle an error, so people usually use that.
Re:A minimal blog engine written in Go, compatible with Ghos... by threeseed on Saturday April 25, 2015 @08:36PM (#9440067)
I'm confused what makes exception handling so troublesome ?

Personally I find them essential in particular for larger codebases. They allow for centralised, consistent error handling behaviour. For example paging application support teams only for certain types of errors.

And you can always emulate explicit error recovery with exceptions. So what is so bad about having the flexibilty to accomodate different styles of error handling.

Re:A minimal blog engine written in Go, compatible with Ghos... by xienze on Saturday April 25, 2015 @10:28PM (#9440298)
Yeah, I don't understand the objection to exceptions either. I _think_ the reason is because people treat them much the same was as errors in C/Go/etc., i.e., "I have to catch them here and recover right away." If you're doing it that way, you're doing it wrong. Design the system such that exceptions can be rethrown (bubbled up) and defer the handling as long as possible.
Re:A minimal blog engine written in Go, compatible with Ghos... by mike_hearn on Sunday April 26, 2015 @02:14PM (#9442691)
Nothing. This is one of those "Go doesn't have it, so it must be bad" things. The way Go handles errors is a throwback to C and was abandoned by literally every single imperative language for good reasons.
Re:A minimal blog engine written in Go, compatible with Ghos... by 4ydx on Sunday April 26, 2015 @03:16AM (#9440850)
Honestly I wish that golang forced you to acknowledge all return values from methods even if you simply ignore them ( _ = Method() ). When I read the docs for any method calls in golang I like being able to see that something returns an error just by looking at the function signature. Certainly I might not know how to handle all the error variations, but not having to decide if I need to wrap something in try/catch... I dunno it just resonates with me.