optakt / flow-dps

Flow Data Provisioning Service
Apache License 2.0
29 stars 13 forks source link

Meta: discuss named return values in interfaces #393

Closed awfm9 closed 3 years ago

awfm9 commented 3 years ago

My opinion on this is that we should name parameters and return values according to the same principle, which is:

// DON'T
type Something interface {
   LoadBlock(blockID flow.Identifier) (block *flow.Block, err error)
}

// DO
type Something interface {
  LoadBlock(flow.Identifier) (*flow.Block, error)
}
// DON'T
type Something interface {
  LoadBlock(uint64) (flow.Identifier, flow.Identifier, error)
}

// DO
type Something interface {
  LoadBlock(height uint64) (blockID flow.Identifier, parentID flow.Identifier, err error)
}

Within an interface, we can use both approaches, depending on what makes sense.