News for hackers. Stuff that matters.
Re:Option and null in dynamic languages by stormbrew on Monday December 08, 2014 @09:23PM (#8720603)
The thing that's always annoyed me about the way go does this, where extra return values are treated somewhat specially to encourage you to actually check them, if your function returns only a success/failure condition you're either forced to return a dummy value for no reason and ignore it, or allow the condition to go unchecked.

Meanwhile, the actual concept of option type has been around for ages and could have been used instead of trying to twist MRV into it.

Thankfully, all the other newer languages are doing the right thing imo.

Re:Option and null in dynamic languages by NateDad on Tuesday December 09, 2014 @04:16PM (#8725812)
Not sure what you mean by needing a dummy value if your function only returns success/failure. That's what a boring old error return is for.

    func foo() error
Re:Option and null in dynamic languages by stormbrew on Tuesday December 09, 2014 @04:42PM (#8725991)
Yes, but unlike having a second result this particular error check need not be touched. To make it so the caller has to check it, I'd have to return a dummy normal return.
Re:Option and null in dynamic languages by NateDad on Wednesday December 10, 2014 @03:24PM (#8731451)
You can always call a function and not assign the return calls to anything.

If you have

func foo() (string, error)

You can still call it thusly:

foo()

However there are tools to check for unchecked errors like this one: https://github.com/kisielk/errcheck