style: strengthen constructor naming and Params struct rules #19

Merged
sneak merged 4 commits from style/constructor-naming-params into main 2026-03-20 07:06:03 +01:00
Showing only changes of commit d83bd08d4d - Show all commits

View File

@@ -138,13 +138,13 @@ last_modified: 2026-02-22
1. Constructors **must** be called `New()`. `modulename.New()` works great if 1. Constructors **must** be called `New()`. `modulename.New()` works great if
you name the packages properly. If the constructor creates an instance from you name the packages properly. If the constructor creates an instance from
an existing value or representation, `From<Something>()` (e.g. `FromBytes()`, an existing value or representation, `From<Something>()` (e.g.
`FromConfig()`) is also acceptable. If the package contains multiple types `FromBytes()`, `FromConfig()`) is also acceptable. If the package contains
and `New()` is ambiguous, `NewThing()` is occasionally acceptable — but multiple types and `New()` is ambiguous, `NewThing()` is occasionally
prefer restructuring packages so each type gets its own package and a plain acceptable — but prefer restructuring packages so each type gets its own
`New()`. Do not invent creative constructor names like `Create()`, `Make()`, package and a plain `New()`. Do not invent creative constructor names like
`Build()`, `Open()` (unless wrapping an OS resource), or `Init()`. If you `Create()`, `Make()`, `Build()`, `Open()` (unless wrapping an OS resource),
see a constructor with a non-standard name, rename it. or `Init()`. If you see a constructor with a non-standard name, rename it.
1. Don't make packages too big. Break them up. 1. Don't make packages too big. Break them up.