Skip to content

Refactor codebase to use value parameters instead of pointers where appropriate #3644

@alexandear

Description

@alexandear

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)

Metadata

Metadata

Assignees

Labels

Breaking API ChangePR will require a bump to the major version num in next release. Look here to see the change(s).enhancementgood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions