refactor selector package layout #236
Labels
effort/hours
Estimated to take one or several hours
exp/intermediate
Prior experience is likely helpful
kind/architecture
Core architecture of project
P2
Medium: Good to have, but can wait until someone steps up
pending/changewindow
The issue is well-defined, but action is pending until we enter a period of accepting changes.
status/ready
Ready to be worked
topic/devexp
Developer Experience
The current
traversal/selector
package works, but I think at this point, after seeing how users interact with it (and what confuses them), we could make some changes that would make it auto-explain itself to users much better.Problem Identification
The main problem with the current arrangement is that it makes it too easy for a new reader to think the
selector.Selector
type is something they should interact with... which is not the case.The
selector.Selector
type is a "complied" thing that's used by other logic to get stuff done; it's often not the data type a user should be doing anything but pass around. Users shouldn't be implementing it; users shouldn't be calling its methods directly themselves; it's not meant to be part of a protocol API itself (its precursors, before "compilation", are!); etc. And yet people see it first, so they keep assuming it will be those things.Proposed Solution
It would be better to have:
traversal/selector/engine
-- contains theengine.Selector
interface, all its implementors, and theCompile
functionstraversal/selector
-- contains the user-facing walk functions, and user-facingCompile
functions (it mostly delegates)traversal/selector/parse
-- contains things like the json-to-dmt jumperstraversal/selector/builder
-- sure, this can come along tooThe packages like
selector/parse
andselector/builder
should just be returning anipld.Node
of the DMT of the Selector.The whole
traversal/selector.*
namespace can be filled with things a typical user should see at first glance. Like: functions that glue theparse
orbuilder
features directly theengine.Compile
and then pass all that straight through to starting aWalk
. Having complete end-to-end features like that visible in the root package about selectors should increase ease-of-use and discoverability drastically.The
traversal/selector
package also becomes free to import other packages likedagjson
without fear, and free to use those to make nice one-step helper functions... because if some user is really dependency-conscious and doesn't want that, they are free to do the additional work to make their code use the low level subpackages directly. This frees us up to be much more helpful to the most typical users.The huge majority of concrete types in the current selector package would all disappear into
selector/engine
and I think that would be for the best. Users need to be aware of those approximately "never".Timeline and Change Strategy
Not immediate. At this time, I'm just making notes on the wish.
This would probably result in some API changes that are technically "breaking", so we'll want to decide when it's time for that. That said: the breakages I would expect to make will be extremely clear at compile time and almost certainly addressable by "sed"-scale updates in downstream consumers.
It's possible we could make these changes nonbreaking by using golang's alias feature heavily, but I'm not actually sure I'd want to do that -- it might obstruct fixing the communicational buggaboo about the
selector.Selector
type being an engine thing that should be mostly unseen, which would reduce what we win with this change. Still worth considering the possibility, though; might be less problematic than I initially fear, or there might be good middle grounds for removing most breakage for most users, etc.The text was updated successfully, but these errors were encountered: