go-simplejson icon indicating copy to clipboard operation
go-simplejson copied to clipboard

Must* methods are inconsistent with the standard library.

Open bmatsuo1 opened this issue 12 years ago • 1 comments

I find the Must* methods to be fairly misleading. In the standard library a Must prefix implies that when the underlying function/method returns an error a runtime panic will be occur. It wasn't until reading the source code that I realized this was not the case. I would like to propose two things:

  • State in the documentation that when the underlying method returns an error that the return value will be the zero value for that type (or the default value).
  • In the next major version, rename this methods to avoid confusion. After thinking of alternatives I think the prefix Just would be more appropriate.

bmatsuo1 avatar Apr 13 '13 21:04 bmatsuo1

That’s a valid point.

But the ideal, IMHO, would be to have Int only return one int value, and have another function, say, CheckInt, that returns an error too.

Also, shouldn’t the error be the first return parameter?

mostafah avatar Aug 19 '13 12:08 mostafah