Skip to content

export internal/config.Modifier#457

Open
jaypipes wants to merge 1 commit intomainfrom
export-modifier
Open

export internal/config.Modifier#457
jaypipes wants to merge 1 commit intomainfrom
export-modifier

Conversation

@jaypipes
Copy link
Copy Markdown
Owner

Exports internal/config.Modifier in alias.go so that dependency injection and mocking tools can do a slightly better type-check than any.

Issue #456

Exports `internal/config.Modifier` in `alias.go` so that dependency
injection and mocking tools can do a slightly better type-check than
`any`.

Issue #456

Signed-off-by: Jay Pipes <jaypipes@gmail.com>
@ffromani
Copy link
Copy Markdown
Collaborator

exporting the Modifer LGTM but I concur we should understand the usecase and the pain of the current API better before to merge this PR.

@pastequo
Copy link
Copy Markdown

I jumped in the discussion since I opened the issue.

IMHO, in general, I would avoid exposing a function and put its parameter type in internal/. It's true that helpers are exposed to create the parameter, but anyone using the go package won't be able to create function on top of yours

With that being said, it's true that the function is practically using any, not the internal type. But if any could be avoid, that would be nice

Just my 0.02$

@jaypipes
Copy link
Copy Markdown
Owner Author

I jumped in the discussion since I opened the issue.

IMHO, in general, I would avoid exposing a function and put its parameter type in internal/. It's true that helpers are exposed to create the parameter, but anyone using the go package won't be able to create function on top of yours

With that being said, it's true that the function is practically using any, not the internal type. But if any could be avoid, that would be nice

Just my 0.02$

@pastequo unfortunately, we can't avoid the use of any in the primary module New() functions because that was the only way we were able to make a backwards-compatible function signature since the original ones used a concrete type (the old *pkg/option.Option struct) instead of an interface. :(

Adding internal/config.Modifier as an exported type, however, should allow you to update your mocking to use ghw.Modifer instead of the mock.AnythingOfType(string) method, no?

@pastequo
Copy link
Copy Markdown

I could argue that you are not strictly backward compatible anyway (at least between 0.16.0 & 0.23.0, I haven't looked into the details) because

Also another argument "against" the backward compatibility is that it might have worked for 1 option (like New(option.WithXXX)) but it wouldn't have worked for 2 and more
New(option.WithXXX, option.WithYYY) would have raised a compilation error as []Options is not usable as a []any

You are still on major 0, so you can take advantage of that. I think I would have prefer either several New or multiple parameters in New and keep the typing. But that is my personal opinion

Regarding the mock thing, I think it's a limitation of gomock, gwh.Modifer is a function, gomock can't match on them

@jaypipes
Copy link
Copy Markdown
Owner Author

I could argue that you are not strictly backward compatible anyway (at least between 0.16.0 & 0.23.0, I haven't looked into the details) because

Sorry, @pastequo. This commit was the one that broke backwards compatibility. :(

option.Option is now a typedef for a function. but used to be a struct. The commit referenced above unfortunately changed the Option struct to be called Options (plural instead of singular) and the Option function typedef accepts a pointer to an Options struct which it mutates. We dropped the ball on this. Really sorry about this!

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