Hacker News new | ask | show | jobs
by badbath 4235 days ago
That's nuts. All of your code now has to check if err != nil, etc.

Furthermore, the sendEmail and validateEmailForm values are essentially ignored and used only for their possible error values.

Why should I wrote my program as if the thing I'm concerned primarily with is errors? Much better to encode the failure into the type. You could have, for example, some function that returns Either[Error, SendEmailAction] where SendEmailAction is a function that, when called, will perform the effect of sending an email. Now I can deal with the happy path by mapping on the right-biased Either.

3 comments

This has been discussed in pretty much every golang thread here on HN :)
When I started go, i also thought it was nuts. And it indeed clutters your code a lot. But in the end, i like it.

Golang is a really simple language, but all the simple concepts, and the lack of OOP, forces you to think more about your code. Also you are forced to think about error conditions.

I'm still playing around with it. So i dont have a final opinion on go.

Not if you use Scala. With Scala, you'd just map or for comprehension over the result.
That's what he covers in his third paragraph...
Well, to be fair it's if you use any language that uses some equivalent of the Maybe Monad.