Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it idiomatic having non-interfaces called like "*er"

Tags:

go

The "Effective Go" states:

By convention, one-method interfaces are named by the method name plus an -er suffix or similar modification to construct an agent noun: Reader, Writer, Formatter, CloseNotifier etc.

bufio.io package contains this:

// Reader implements buffering for an io.Reader object.
type Reader struct {
    buf          []byte
    rd           io.Reader
    r, w         int
    err          error
    lastByte     int
    lastRuneSize int
}

Is it idiomatic having structs named like "*er"? Especially in this case it's a struct with the same name as io.Reader which is an interface.

like image 454
warvariuc Avatar asked Sep 30 '22 10:09

warvariuc


1 Answers

If it's not in Effective Go or the specs then it's a matter of opinion really, I'd say it's fine as long as it makes sense.

Using bufio.Reader or bytes.Reader as an example, they make perfect sense to be named that way.

like image 160
OneOfOne Avatar answered Oct 03 '22 00:10

OneOfOne