Skip to content

Policy on using pointers/values in structs for receiving data from GitHub servers. #537

Closed
@dmitshur

Description

@dmitshur

I'm making this issue to discuss a point that came up while reviewing #534. /cc @alindeman

Background

In #534, @alindeman answered my questions:

@shurcooL: What's the reason to use string value rather than *string pointer, as is commonly done in other structs?
@shurcooL: What's the reason to omit ,omitempty option, contrary to most similar structs we have?

@alindeman: Thinking back to the conversation we had over in #512, I thought that since--as far as I can tell--these attributes will always be returned from the API, we could specify them as non-pointer types.

One key difference is that the conversation in #512 was primarily about the request structs - structs that are used to send values to github servers. The affect on structs for receiving and unmarshaling data from github servers was inadvertent and discovered at the end, and we decided to go ahead with it because it was very minor. This PR is all about the structs for receiving from the start, that's why I want to think about it more carefully.

As I understood it up until now (before doing the following research), the main reason pointers are used for most receiving structs is to be able to tell when a field is absent vs when it's present but set to zero.

That's what I saw in #79. That links to #19 where the initial discussion took place, and 3072d06 is the implementation commit. However, as I read over #19 in more detail now, I was surprised to see that the main motivation to have pointers there seemed to be for the ability to set fields, because at the time many structs were reused for setting and getting. /cc @willnorris

It's interesting that we've seemingly evolved towards dedicated Request structs for editing/updating operations (e.g., https://godoc.org/github.com/google/go-github/github#IssueRequest and https://godoc.org/github.com/google/go-github/github#Issue; https://godoc.org/github.com/google/go-github/github#BranchRestrictionsRequest and https://godoc.org/github.com/google/go-github/github#BranchRestrictions, also see #528, etc.). This was typically forced on us by certain new GitHub endpoints that had differences in the JSON they expect when editing/updating a resource. Especially whey they have required fields in the request.

In #512 we discussed and came to the conclusion that it makes sense to use values rather than pointers for required fields in the request structs.

Conclusion

So in the end, I think that it's valid to also use values rather than pointers for mandatory fields (i.e., those that are guaranteed to be present by GitHub API).

However, one limitation of that is that GitHub API documentation doesn't typically specify fields in the response as mandatory/required, so it's hard to be sure they'll always be present.

One concern is that it also introduces some inconsistency against all the other structs we have that use pointers everywhere.

Next Steps

As a result, I'm a little torn and unsure about what we should do. Do we maintain consistency and keep using pointers everywhere? Do we allow values in certain places where it seems like they're always going to be included? Do we try to convert more things to values?

We're also more constrained in changing existing structs because of desire to not break API without meaningful gains, whereas we can choose what to do for new structs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions