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

Use named specs instead of predicates #76

Closed
bhb opened this issue Nov 3, 2018 · 0 comments
Closed

Use named specs instead of predicates #76

bhb opened this issue Nov 3, 2018 · 0 comments

Comments

@bhb
Copy link
Sponsor Contributor

bhb commented Nov 3, 2018

Currently speculative uses predicates like ifn? and seqable? in the specs. This produces correct specs (and is an idiomatic use of spec). However, I think using named specs instead of predicates is a better approach for speculative, since it is a set of specs shared across the community.

I suggest that all predicates should be wrapped in a spec. For instance, instead of using ifn?, we could define

(s/def ::ifn ifn?)

and then use ::ifn everywhere.

Benefits

  • Most importantly for my purposes, it's easy to store additional information about named specs in separate registries. For instance, expound can add human-readable error messages. This isn't easy to do with predicates (due to differences in how CLJ and CLJS resolve symbols) and it's also pretty invasive: while it's reasonable for a user to register a custom error message for :speculative.core/ifn, it's not clear that it's a good idea to register one for ifn?, which would affect ALL specs, not just ones defined in speculative. Note that the proposal to add metadata to specs also involves associating keyword names with metadata, so if that proposal is adopted, this change will continue to enable users to register metadata.

  • It's easy to attach a common generator to a spec. See ::map-entry as an example.

  • If end users use check, they can use the :gen option (a "map from spec names to generator overrides") to provide generators for named specs.

Downsides

  • One more thing to keep in mind when writing specs (it's easy to forget to use ::ifn instead of ifn?)
  • One more "layer" of wrapping, which will be visible in the explain-data
  • If, for some reason, this practice is considered ill-advised by core spec team, this could run against the "goal is to be rendered obsolete by these or similar specs"
bhb added a commit to bhb/speculative that referenced this issue Nov 3, 2018
bhb added a commit to bhb/speculative that referenced this issue Nov 3, 2018
slipset pushed a commit that referenced this issue Nov 4, 2018
borkdude pushed a commit that referenced this issue Nov 4, 2018
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

No branches or pull requests

1 participant