-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Many methods in the codebase, such as:
func (s *RepositoriesService) CreateRelease(ctx context.Context, owner, repo string, release *RepositoryRelease) (*RepositoryRelease, *Response, error)
use pointer parameters (e.g. *RepositoryRelease
) even when the function doesn't mutate the input. This appears to be a result of convention or copy-paste, not a performance-driven choice.
For instance, in CreateRelease
, the RepositoryRelease
struct is relatively large (~15+ fields), but most of its fields are pointers themselves. As such, passing it by value would have negligible performance impact in typical API usage. Moreover, value semantics would improve clarity, especially for required arguments that aren't modified.
To improve API design consistency and safety, we should:
-
Audit method signatures that accept pointer structs as input
-
Change them to accept values when:
-
The input is required (not optional)
-
The function does not modify the input
-
-
Optionally introduce dedicated input structs for specific operations (e.g.
CreateRepositoryRelease
with only the fields needed for creation)
Note: This would be a breaking change and should be handled carefully, possibly across multiple PRs.
Originally posted by @gmlewis in #3636 (comment)