From e72b2d3522c073104b21ace2a731bd87061b8d86 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 17 Mar 2026 19:53:31 -0700 Subject: [PATCH 1/4] style: strengthen constructor naming and Params struct rules - Constructors must be New(), From(), or NewThing() (multi-type pkg) - Strongly discourage creative names (Create, Make, Build, Init) - Constructors must use Params struct for 2+ arguments, no exceptions - Single obvious argument (ctx, bytes) is the only exception --- prompts/CODE_STYLEGUIDE_GO.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/prompts/CODE_STYLEGUIDE_GO.md b/prompts/CODE_STYLEGUIDE_GO.md index 4b0a1a9..d431fed 100644 --- a/prompts/CODE_STYLEGUIDE_GO.md +++ b/prompts/CODE_STYLEGUIDE_GO.md @@ -136,8 +136,15 @@ last_modified: 2026-02-22 1. Provide a .gitignore file that ignores at least `*.log`, `*.out`, and `*.test` files, as well as any binaries. -1. Constructors should be called `New()` whenever possible. `modulename.New()` - works great if you name the packages properly. +1. Constructors **must** be called `New()`. `modulename.New()` works great if + you name the packages properly. If the constructor creates an instance from + an existing value or representation, `From()` (e.g. `FromBytes()`, + `FromConfig()`) is also acceptable. If the package contains multiple types + and `New()` is ambiguous, `NewThing()` is occasionally acceptable — but + prefer restructuring packages so each type gets its own package and a plain + `New()`. Do not invent creative constructor names like `Create()`, `Make()`, + `Build()`, `Open()` (unless wrapping an OS resource), or `Init()`. If you + see a constructor with a non-standard name, rename it. 1. Don't make packages too big. Break them up. @@ -149,9 +156,14 @@ last_modified: 2026-02-22 1. Use descriptive names for modules and filenames. Avoid generic names like `server`. `util` is banned. -1. Constructors should take a Params struct if they need more than 1-2 - arguments. Positional arguments are an endless source of bugs and should be - avoided whenever possible. +1. Constructors **must** take a `Params` struct (or `ThingParams` when + `NewThing()` is used). Positional arguments for constructors are an endless + source of bugs — they make call sites unreadable, invite wrong-order errors + that the compiler can't catch when types coincide, and force every caller to + update when a new field is added. The only exception is a constructor that + takes exactly one argument whose meaning is obvious from context (e.g. + `New(ctx)` or `FromBytes(b)`). Two or more arguments → use a Params struct, + no exceptions. 1. Use `context.Context` for all functions that need it. If you don't need it, you can pass `context.Background()`. Anything long-running should get and -- 2.49.1 From 4c643d1aa217d7f7429792b49a72758636277ef3 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 17 Mar 2026 19:57:28 -0700 Subject: [PATCH 2/4] style: Params struct required even for single arguments Only exception: stupidly obvious single args (featureflag.New(true)). When in doubt, use Params. --- prompts/CODE_STYLEGUIDE_GO.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/prompts/CODE_STYLEGUIDE_GO.md b/prompts/CODE_STYLEGUIDE_GO.md index d431fed..58a72ff 100644 --- a/prompts/CODE_STYLEGUIDE_GO.md +++ b/prompts/CODE_STYLEGUIDE_GO.md @@ -157,13 +157,14 @@ last_modified: 2026-02-22 `server`. `util` is banned. 1. Constructors **must** take a `Params` struct (or `ThingParams` when - `NewThing()` is used). Positional arguments for constructors are an endless - source of bugs — they make call sites unreadable, invite wrong-order errors - that the compiler can't catch when types coincide, and force every caller to - update when a new field is added. The only exception is a constructor that - takes exactly one argument whose meaning is obvious from context (e.g. - `New(ctx)` or `FromBytes(b)`). Two or more arguments → use a Params struct, - no exceptions. + `NewThing()` is used), even for a single argument. Named fields in a Params + struct are always clearer than positional arguments. Positional arguments + for constructors are an endless source of bugs — they make call sites + unreadable, invite wrong-order errors that the compiler can't catch when + types coincide, and force every caller to update when a new field is added. + The only exception is when the single argument is stupidly obvious from + context — e.g. `featureflag.New(true)` or `thing.NewFromReader(r)`. When in + doubt, use a Params struct. 1. Use `context.Context` for all functions that need it. If you don't need it, you can pass `context.Background()`. Anything long-running should get and -- 2.49.1 From d83bd08d4d83253a5ebcb4ca06023d43602dc431 Mon Sep 17 00:00:00 2001 From: clawbot Date: Tue, 17 Mar 2026 21:41:25 -0700 Subject: [PATCH 3/4] style: fix prettier formatting in constructor naming section --- prompts/CODE_STYLEGUIDE_GO.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/prompts/CODE_STYLEGUIDE_GO.md b/prompts/CODE_STYLEGUIDE_GO.md index 58a72ff..6794ed5 100644 --- a/prompts/CODE_STYLEGUIDE_GO.md +++ b/prompts/CODE_STYLEGUIDE_GO.md @@ -138,13 +138,13 @@ last_modified: 2026-02-22 1. Constructors **must** be called `New()`. `modulename.New()` works great if you name the packages properly. If the constructor creates an instance from - an existing value or representation, `From()` (e.g. `FromBytes()`, - `FromConfig()`) is also acceptable. If the package contains multiple types - and `New()` is ambiguous, `NewThing()` is occasionally acceptable — but - prefer restructuring packages so each type gets its own package and a plain - `New()`. Do not invent creative constructor names like `Create()`, `Make()`, - `Build()`, `Open()` (unless wrapping an OS resource), or `Init()`. If you - see a constructor with a non-standard name, rename it. + an existing value or representation, `From()` (e.g. + `FromBytes()`, `FromConfig()`) is also acceptable. If the package contains + multiple types and `New()` is ambiguous, `NewThing()` is occasionally + acceptable — but prefer restructuring packages so each type gets its own + package and a plain `New()`. Do not invent creative constructor names like + `Create()`, `Make()`, `Build()`, `Open()` (unless wrapping an OS resource), + or `Init()`. If you see a constructor with a non-standard name, rename it. 1. Don't make packages too big. Break them up. -- 2.49.1 From a8a469ed3108437da157b59ed3fb774060ae0b17 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 17 Mar 2026 21:49:15 -0700 Subject: [PATCH 4/4] fix: update last_modified date in CODE_STYLEGUIDE_GO.md --- prompts/CODE_STYLEGUIDE_GO.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompts/CODE_STYLEGUIDE_GO.md b/prompts/CODE_STYLEGUIDE_GO.md index 6794ed5..043e8f1 100644 --- a/prompts/CODE_STYLEGUIDE_GO.md +++ b/prompts/CODE_STYLEGUIDE_GO.md @@ -1,6 +1,6 @@ --- title: Code Styleguide — Go -last_modified: 2026-02-22 +last_modified: 2026-03-18 --- 1. Try to hard wrap long lines at 77 characters or less. -- 2.49.1