REFACTOR: More information of what to refactor #1
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
Ready for Development
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No project
No Assignees
2 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: anthrove/e621-sdk-go#1
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi @daskadse,
I'm working on refactoring the SDK, there is a branch called refactor where I already started to work on it. You mentioned having some ideas/insights, and I'd love to hear them.
Could you share a list of things to change or tasks to tackle? Your input would be helpful in making sure we're on the right track.
Thanks a bunch!
My main gripe is the inconsistency in the high level API design. Some functions directly request the endpoint (to be fair, these are in implementation just now):
Some don't do any request, but instead return the builder which has to be executed:
Some actually do do a request, but you wouldn't know because you still get a builder returned:
And then there is the ambiguity of getting a builder for paginated content (like favorites) which can be executed just like any other request builder, but only results in getting results from the first page:
Apart from that, there's some pretty poor naming, like
GetFavoritesForUser
being a builder factory andGetNFavoritesForUser
being a builder consumer, which is in no way clear. It also seems a little counter-intuitive that you need to call the method onclient
again (I know the architectural reason for this, but I don't like it).For a nice, coherent API, the pattern used should be consistent. That can be a builder pattern, but would look something more like this:
In fact, I think the builder pattern is pretty good for this, considering its whole point is to collapse many possible function definitions because of alternative arguments into one readable statement. However, this would architecturally require yet another full builder implementation for most types of request for the high level API.
The alternatives would be to either use different functions which do the requests directly (which would need to be a lot), immediately returning the results:
Or to work with optional arguments via variadic functions which contain optional additional configuration:
Issue is that this only works for optional arguments, not for either/or arguments (like username/userID) and that readability is in my eyes worse than with a builder pattern. It is however still a lot better than exploding it all into separate functions and is less work to implement than another layer of builder pattern. Also, compared to the builder pattern, it is technically stricter at compile time, except if you create the builder with type state, but that would be hell in go, so it's not really an option. Therefore, you'd totally be able to create invalid state with the builder which would only error at runtime, which is not the case with optional arguments (at least not if any combination of them is allowable).
REFCTOR: More information of what to refactorto REFACTOR: More information of what to refactor