Better HN
topnewbestaskshowjobs
Log inSign up

yapp0

1 karma · joined Mar 23, 2026 (8mo ago) · 2 submissions

Submissions

comment 8mo ago · link · parent

Go struct initialization doesn't provide a way to enforce that all required fields are set.

That becomes painful when a struct evolves: if you add a new field that is required from a business perspective, existing struct literals still compile until every call site is updated manually.

Constructors help but they don't scale well either, since argument lists quickly become hard to maintain.

I built a code generator tool papa-carlo that creates builders which enforce required fields at compile time. Missing fields result in a compile error rather than a runtime bug.

I wrote a short blog post about the motivation here: https://yappo.cc/posts/2026-02-16-papa-carlo

Would love feedback. Curious if others have run into this problem or solved it differently.

2.

Go builder generator with compile-time required field enforcement(github.com ↗)

2 points · by yapp0 · 8mo ago · 2 comments