Skip to content

encoded: Unalias interfaces #928

Open
@abhinav

Description

@abhinav

The go.uber.org/encoded package declares three interfaces as
aliases of internal package versions of those interfaces.

package encoded

type DataConverter = internal.DataConverter
type Value = internal.Value
type Values = internal.Values

This is both, unnecessary and undesirable.

It is unnecessary because interfaces in Go are implicit. Unless you're
doing something very specialized, where interface identity matters more
than interface compliance, you can just redeclare the interfaces in the
encoded package and things will continue to work.

package encoded

type Value interface {
  HasValue() bool
  Get(valuePtr interface{}) error
}

Any value that satisfies internal.Value will also satisfy
encoded.Value.

You can even add a bidirectional compile-time check to verify that the
interface doesn't go out of sync with its internal variant.

var (
  _ Value = (internal.Value)(nil)
  _ internal.Value = (Value)(nil)
)

It is undesirable because it makes it difficult for users to use the
interface. They cannot just look at the godocs; they have to dig into
the internal packages. It also negatively affects the behavior of
tooling like mockgen (golang/mock#244).


Given this, is there a strong reason to keep the aliases? Is interface
identity necessary or will compliance suffice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementtestRelated to testingup-for-grabsIssues that are good entry points for those new to Cadence that want to contribute

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions