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

refactor(api): use structs #376

Merged
merged 3 commits into from
Sep 11, 2020
Merged

refactor(api): use structs #376

merged 3 commits into from
Sep 11, 2020

Conversation

sh0rez
Copy link
Member

@sh0rez sh0rez commented Sep 10, 2020

Refactors our API away from the Modifier pattern to plain old struct arguments.

  • This requires less boilerplate. No longer a Setter must be created for each possible field
  • Logical separation: Using struct embedding, fields can be properly grouped and scoped for their respective action, etc. This also requires less copying around in memory
  • Stricter checking: Every action got its own composed struct type, so only those fields can be set that actually make sense.

Not quite sure who to assign for review on this. This is intended as a refactor in the strict sense, being a no-op

This converts all of the public API to no longer take a wild variety of
modifier functions, but instead clearly defined structs that only allow
setting those properties, that are actually relevant to that specific
struct.

This not only reduces the amount of boilerplate required, but also makes
the API more discoverable and defines it more clearly.

THIS IS A BREAKING CHANGE
Adapts all commands to the new struct based API style
@malcolmholmes malcolmholmes mentioned this pull request Sep 11, 2020
@sh0rez sh0rez requested a review from sdboyer September 11, 2020 12:02
@sdboyer sdboyer self-assigned this Sep 11, 2020
Copy link

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm usually a little wary of type embedding when there's methods involved - usually, people are trying to simulate class inheritance and end up having a bad day - but flattening pure config/opts-shaped value objects is a good case for it.

And, as you noted, use of the variadic opts pattern here wasn't great, as (i'm inferring? didn't actually verify) it allowed for config values to be passed to some commands that were not applicable to the command. i tend to reserve use of that pattern to situations where a) every possible value implementing the opt type is applicable to functions that receive the opt, and b) the behavior being controlled by the opts is variable enough that the struct just feels (subjectively) like a random grab bag.

👍

opts.apply.AutoApprove = b
}
}
type JsonnetOpts = jsonnet.Opts
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you type aliasing so that the embedded property on Opts is named Opts.JsonnetOpts instead of Opts.Opts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! And also because I prefer the surface of this package to only be consisted of itself, so consumers do not also need to import pkg/jsonnet.

Only pkg/tanka is considered public-facing, while the others are more-or-less internal packages that are public so others could hack on them.

@sh0rez sh0rez merged commit 6584a37 into master Sep 11, 2020
@sh0rez sh0rez deleted the refactor-api branch September 11, 2020 15:26
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