Been thinking about how those constructors balloon over time. Starting simple with NewHTTPClient(host, timeout) is clean and easy. But add more params like auth tokens, retries, user agents, TLS flags... and by sprint 8, the call looks like a mystery puzzle: which arg is what again?
Tried the config struct approach—it’s better at the call site, but you still have to set all fields or guess if zeros mean “default” or “oops.” Then I revisited the functional options pattern. It’s not fancy magic, just a neat Go idiom where you pass option functions to tweak defaults. This keeps constructors simple, explicit, and flexible. Plus, adding new options later doesn’t break existing code.
I’m curious—do you prefer config structs or functional options for expanding APIs? #golang #apiDesign #functionaloptions #productmanagement
If you want a deep dive, here’s a solid write-up on it: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
