3 ms·
Not GP, but I've sometimes found libraries implementing similar concepts differently causing issues. E.g. libraryA.Result struct { Err error
by lenish 6y ago
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.
- mrkeen 6y agoThis is what interfaces are for. Let your caller bring their own error type and instantiate your library code over that.