4 ms·
> Say you put a single type Foo in its own package to ensure that nothing ever — intentionally or unintentionally — touches its unexported (private) fields. Th
by sagichmal 7y ago
> Say you put a single type Foo in its own package to ensure that nothing ever — intentionally or unintentionally — touches its unexported (private) fields.
This is not a good reason to move a type to its own package. Packages are for grouping related functionality.
- erik_seaberg 7y agoPackages have to be used for access control as long as there’s no other way to do it. You’re committing to support uses of anything you make public.
- sagichmal 7y agoWhat? Exporting a type or field is an opt-in decision, you don't need a special package per type to do it. If the fear is that other types or functions in the same package can access the unexported fields, that's unavoidable, making a new package per type doesn't reduce the risk.