Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not GP, but I've sometimes found libraries implementing similar concepts differently causing issues.

E.g.

    libraryA.Result struct {
        Err error
        Data SomeDataType
    }

    libraryB.Result struct {
        err string
        Data SomeDataType
    }
    func (r libraryB.Result) Error() string {
         return r.err
    }
Now you have two different implementations of the same fundamental idea, but they each require different handling. In Go, where many things simply return an error type in addition to whatever value(s), you would now have three different approaches to error handling to deal with as opposed to just whatever the language specified as the best practice.


This is what interfaces are for.

Let your caller bring their own error type and instantiate your library code over that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: