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

Use option structs instead of arguments #155

Open
schrej opened this issue Nov 16, 2021 · 1 comment
Open

Use option structs instead of arguments #155

schrej opened this issue Nov 16, 2021 · 1 comment

Comments

@schrej
Copy link

schrej commented Nov 16, 2021

With the recent addition of additional arguments with v2 the functions became very hard to use (or rather, even worse than before).

Without advanced IDE support that shows the parameter names inline (only GoLand for now) it's very hard to identify the arguments, especially when omitting a lot of them. A common pattern in Go is using a struct as a single argument, that then contains the different options. It has several advantages over the current approach:

  • shorter method signature
  • optional arguments can simply be omitted
  • used arguments are easy to identify as you have to put the attribute name in front of them
  • easy to expand with further attributes without breaking changes

for example:

hostRecord, err = objMgr.CreateHostRecord(true, false, deviceFQDN, networkView, "default."+networkView, subnet.String(), "", "", "", "", "", false, 0, "", make(ibclient.EA), nil)

could become

hostRecord, err = objMgr.CreateHostRecord(CreateHostRecordOptions{
	NetworkView: networkView,
	DNSView: "default."+networkView,
	EnableDNS: true,
	IPv4CIDR: subnet.String(),
})

The latter is a lot easier to read and understand quickly. While it would be another breaking change in a short time, it's a worthy improvement in my opinion.

Also, if you would've used this approach before, a lot of the breaking API changes with v2 wouldn't have been breaking changes.

@skudriavtsev
Copy link
Contributor

Thank you for your report. Yes, there is such a problem. There were reasons to move to the form of passing parameter values as a literal list. But this was considered as a temporary solution.

Now we are on the way of reconsidering the API of the Go-client for WAPI and stabilizing it to avoid possibilities of breaking changes in the future as much as possible. And your proposal is one of the main points. Thank you again.

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

No branches or pull requests

2 participants