From 4c643d1aa217d7f7429792b49a72758636277ef3 Mon Sep 17 00:00:00 2001 From: user Date: Tue, 17 Mar 2026 19:57:28 -0700 Subject: [PATCH] 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