3 ms·
I disagree. Return interfaces where it makes sense. E.g., returning type Buffer interface { io.Writer io.ByteWriter WriteString(str
by barsonme 10y ago
I disagree. Return interfaces where it makes sense. E.g., returning
type Buffer interface {
io.Writer
io.ByteWriter
WriteString(string) (int, error)
...
}
from `bytes.NewBuffer' would be a bit absurd. But returning an interface (`io.Reader') from `io.MultiReader' makes more sense than returning some sort of structure.
I think the author was getting at how one should always return explicit zero values _or_ explicit non-zero. E.g.,
func GetACat() (Cat, error) {
cat, err := getCatInternalOrSomething()
if err != nil {
return nil, err
}
return cat, nil
}