Skip to content

Use metadata key for fn-body spec generation. #27

@pithyless

Description

@pithyless

This is an issue that started out as a comment to #26

Existing Feature

Proposed Problem (1)

Proposed Solution (1)

  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.
  2. The feature is not mentioned :ghostwheel.core/ghostwheel-config nor ghostwheel.utils/ghostwheel-default-config
  3. Honestly, as a user - I am still not sure if and how I can disable this feature.
  4. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions