3 ms·
so the return type of this little program is "error" and nil if no error?
by xwowsersx 12y ago
so the return type of this little program is "error" and nil if no error?
- icebraining 12y agoYes. It's either a value that implements the 'error' interface or nil.
- badbath 12y agoThat'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.
- ecopoesis 12y agoNot if you use Scala. With Scala, you'd just map or for comprehension over the result.
- icebraining 12y agoThis has been discussed in pretty much every golang thread here on HN :)
- TeeWEE 12y agoWhen 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.