-
Notifications
You must be signed in to change notification settings - Fork 112
Differ between a compiled Indexand an IndexBuilder #109
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
Comments
+1 |
I have been thinking a little bit about this for a while, and I have just come to a perhaps slightly unexpected conclusion. I think that an uncompiled Index and a compiled Index is not really the same thing, and does not have the same interface. I will collaborate a little-bit on this... An uncompiled Index has the following use-case and properties:
A compiled Index has the following use-cases and properties:
The same can in principal be said about Resource and perhaps even Scheam and FieldValidator implementations, but we can set a line on how far we want to drag this to not create to much work to ourselves. For this issue at least, let's limit it to only touch the Following from this, we could imagine we have the following types & interfaces:
Optionally, we do the same for |
PS! This design also completely guards against users using an uncompiled index by mistake, as doing so would now be a compiler error. This of course also eases the documentation, as we no longer need to put warnings in the README alá:
|
I like the idea. |
EDIT: The orginal issue was to return a concrete type from NewIndex. The issue is now about differing between an IndexBuilder and a compiled Index which serve different usage patterns and requirements. See comments for more details
Original idea
@rs, I am raising this as a potential enchantment only.
It appears to be an idiom in Go to return concrete types, and accept interfaces.
resource.NewIndex()
is breaking this idiom. I see the following benefits for correcting it:index.Compile()
would no longer be a "hidden" function, so user would not have to type-cast the returned index to a Compiler instance if using the returned Index without the rest handlers.These are not huge benefits, but if there is no obvious downside to the change, except for a limited change to the public API, it might be worth-while. There are also some consequences that could come out of how we fix this that we need to consider.
resource.Resource
implements the Index interface. Could/should Bind accept a version of the Index interface? (probably not)Background: General information on the idiom
Some blogs on the subject:
TL;DR with some added personal experience:
Generally, returning the concrete type makes sense because:
Likewise, it makes sense to accept interfaces because:
Sometimes these points doesn't match with our goals, and then it's probably correct to break the idiom.
The text was updated successfully, but these errors were encountered: