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

Remove duplicate value fields #108

Merged

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Dec 27, 2018

While reading over the code I noticed a couple fields on the Method struct that I found particular hard to understand. After reading over the code I realized these fields held copies of values from Fake. They appear to exist solely to render values into the template, but do not feel like natural properties of a Method type.

I noticed that at the bottom of https://golang.org/pkg/text/template/#hdr-Variables it says $ is always set to the initial value of .. Using $ I was able to remove these copied values and use the original value from the Fake.

Fewer fields, especially fields that contain values which are copies of other values, should make the code easier to understand.

dnephin and others added 4 commits December 27, 2018 00:02
This value was being copied from Fake for the sole purpose of rendering
a template. The FakeName field does not make much sense as a field on a
Method struct, it is not a property of a method.

Instead of copying the value to a struct, change the templates to
reference the root object using $, which is always the initial value of
'.' when a template rendering is executed.
This value was being copied from Fake for the sole purpose of rendering
a template. The FakePackage field does not make much sense as a field on a
Method struct, it is not a property of a method.

Instead of copying the value to a struct, change the templates to
reference the root object using $, which is always the initial value of
'.' when a template rendering is executed.
@joefitzgerald joefitzgerald merged commit 2bb60b4 into maxbrunsfeld:master Jan 8, 2019
@joefitzgerald
Copy link
Collaborator

Thanks for the $ hint; TIL!

@dnephin dnephin deleted the remove-duplicate-value-fields branch January 8, 2019 16:10
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.

2 participants