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

crates/doc: refactor inference module into shape module and friends #1137

Merged
merged 2 commits into from
Aug 9, 2023

Conversation

jgraettinger
Copy link
Member

@jgraettinger jgraettinger commented Aug 5, 2023

See individual commits. No (intentional) behavior changes in this PR, it's just a refactor.


This change is Reviewable

@jgraettinger jgraettinger marked this pull request as ready for review August 5, 2023 20:49
Copy link
Contributor

@jshearer jshearer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- I didn't check and make sure that each moved chunk works exactly the same as it did before, but it looks right and is way better broken up like this. inference.rs being almost 4k lines long was too much


// Prune any locations in this shape that have more than the allowed fields,
// squashing those fields into the `additionalProperties` subschema for that location.
pub fn enforce_field_count_limits(slf: &mut Shape, loc: Location) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue, but I am curious why this isn't in an impl Shape block, or rather what heuristic you're using to determine when to use a free function vs an impl. I had been using impls mainly for discoverability: we have a pretty big codebase, and being able to write my_shape. and have my IDE give me a list of functions I can call on Shape feels useful. Is it that we're not confident in this API and don't want to "expose" it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it that we're not confident in this API and don't want to "expose" it?

That's some of it, yes.

It's also orthogonal to what Shape is and does, and isn't core to it's function. Especially once you re-interpret widen to return "did this widen change the Shape anywhere?". widen is a core capability of Shape, while enforce_field_count_limits is business logic applied to a Shape. And a big distinction in my mind, is that we can define lots of different heuristics and trade-offs for when to prune stuff out of a Shape, but there's only one sensible widen operation.

Also, as a general strategy, I definitely recommend starting out with free functions and only attaching them to structs when it's really obvious they belong. It makes refactoring way easier, especially in the early stages of a subsystem when you're unsure how everything fits together.

As a discipline, I find a lot of engineers will jump too quickly into an object-plus-behaviors-oriented mindset and then get stuck when their initial conceptual modeling doesn't match evolving requirements. Free functions that you can refactor and move as-needed avoids that mental trap, because it defers bestowing "object-ness" onto what are, at the end of the day, just a pile of bytes.

doc::shape has a variety of other submodules, some of them public and
others not, which focus on particular features and capabilities of Shape.

No behavior changes, and no significant changes to tests,
though I moved quite a few things around.
Update to use doc::shape and friends instead.
@jgraettinger jgraettinger merged commit ddd8f01 into master Aug 9, 2023
5 checks passed
@jgraettinger jgraettinger deleted the johnny/schema-infra branch August 9, 2023 19:05
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.

2 participants