nspcc-dev / neofs-sdk-go

Go implementation of NeoFS SDK
Apache License 2.0
6 stars 14 forks source link

Replace type wrappers with `struct` #214

Open cthulhu-rider opened 2 years ago

cthulhu-rider commented 2 years ago

In current implementation some types (example) are defined as wrappers over other types:

type TT T

In type docs we try to prevent direct type conversion since it can lead to compatibility loss:

var t TT
tt := TT(t)

Instead we provide methods to do it like:

func (x *TT) fromT(t T) {
  *x = TT(t)
}

If we'll later change type definition to:

type TT struct {
  t T
}

direct conversion will be broken, while method won't.

Maybe we want to prevent type conversion by hard encapsulation and define all such type as struct with private fields?

I also suggest to comprehensively explore the difference between the two approaches, and generally accepted practices.

roman-khimov commented 1 year ago

I'd keep it as is, simple and good enough.

cthulhu-rider commented 1 year ago

Such typing does not allow internal type changes. If we will support types from neofs-api-go within v1.x, then we can keep it as is. Otherwise we will be locked in internal type restructuring.

roman-khimov commented 1 year ago
  1. Most likely, you won't need it.
  2. api-go can be extended if you really need to do it, new methods are OK then.
  3. A new type can be added as well if we really really need it.
cthulhu-rider commented 1 year ago

Full-private struct covers all cases more user-friendly. But I don't mind leaving the current typing since docs advise avoid casting.