-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Milestone
Description
This is an issue that started out as a comment to #26
Existing Feature
Proposed Problem (1)
- Effortless spec-based stub generation in nil-body functions for rapid prototyping is a potentially useful tool
- Currently this is enabled by default, which is a jarring experience if one is not aware of this feature; as explained in A strange problem: function returning nil instead returns random numbers #26 (comment)
Proposed Solution (1)
- Improve documentation: the feature is mentioned in the readme #introduction, but that would also be a good place to mention (or link to) how to disable/enable it.
- The feature is not mentioned
:ghostwheel.core/ghostwheel-confignorghostwheel.utils/ghostwheel-default-config - Honestly, as a user - I am still not sure if and how I can disable this feature.
- It's a jarring experience if one is not aware of it, so make it opt-in via configuration.
Alternative Feature
Once I started thinking about this problem, I'd like to suggest an alternative approach.
Proposed Problem (2)
- Low-effort spec-based stub generation of functions for rapid prototyping is a potentially useful tool
- The principle of least-surprise is important to Clojure developers
- Configuration is global on/off, while syntax can be applied locally
- The road from "cool dev tool" to "potential bug in production" is paved with good intentions (i.e. how easy is it for dev to accidentally not implement a function, but have it "work" during dev/testing?)
Proposed Solution (2)
Instead of global enabled/disabled feature of nil-body functions, we could configure it via metadata (similar to ::g/trace). That way:
- requires no configuration
- is opt-in for any function
- concise enough to easily type (small overhead vs an implicit global configuration)
- explicit in what is not yet implemented (easy to grep in codebase, etc.)
(>defn ^::g/fake some-string-to-int
[x] [string? => int?]
nil)
We could even take this even a step-further and remove the nil-body constraint. Any time we add the metadata key ::g/fake to a function, it will simply ignore the body and generate random data from spec. Possible use-cases for this? Stubbing out in development an I/O function, etc.
What we call the metadata key itself (::g/fake) is open to discussion. I'm just wondering if this idea has any legs. Thoughts?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels