Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate pointer-field ordered maps. #824

Merged
merged 4 commits into from
Apr 28, 2023
Merged

Generate pointer-field ordered maps. #824

merged 4 commits into from
Apr 28, 2023

Conversation

wenovus
Copy link
Collaborator

@wenovus wenovus commented Apr 28, 2023

Just generating what's in #823

wenovus added 3 commits April 28, 2023 11:30
Initially I made the choice to use a non-pointer so that the user would
not need to initialize this field before using it.

The advantage is all methods can hang off of the type rather than
needing methods to hang off the parent type in order to nil-check and
initialize.

However, this creates problems that a pointer field solves:
1. Avoid needing value-receivers in order to make the field satisfy
   certain interfaces (e.g. ygot.GoStruct). Mixing receiver types is
   confusing for the reader.
2. Helps avoid awkward reflection code that need to access the pointer
   receiver methods since `CanAddr()=false` for non-pointer objects:
   https://go.dev/play/p/5vYVVUS-GfD
3. Users of ygot are used to declaring every struct as pointers, so
   using pointers makes things congruent with existing generated code.
@wenovus wenovus requested review from DanG100 and bormanp April 28, 2023 21:52
@coveralls
Copy link

Coverage Status

Coverage: 90.122% (-0.007%) from 90.129% when pulling df0cb3c on ordered-map-ptr-gen into 70236cc on ordered-map-ptr.

Base automatically changed from ordered-map-ptr to master April 28, 2023 21:57
@wenovus wenovus merged commit 97fb230 into master Apr 28, 2023
@wenovus wenovus deleted the ordered-map-ptr-gen branch April 28, 2023 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants