6 ms·
Yeah, you're right. I would love if every Clojure function came with an example input and output. What I meant to suggest is that my docstring example is somet
by danneu 13y ago
Yeah, you're right. I would love if every Clojure function came with an example input and output.
What I meant to suggest is that my docstring example is something that could be expressed in code.
- zeckalpha 13y agoThis would let you run tests, too: https://en.wikipedia.org/wiki/Doctest https://en.wikipedia.org/wiki/Doctest On the other hand, why not just make it statically typed and list the types for each function?
- freshhawk 13y agoA friend of mine has been doing similar things with the Swagger documentation spec (https://developers.helloreverb.com/swagger/ https://developers.helloreverb.com/swagger/) While browsing the docs in a web browser you can fill out some fields for input and see what the output for that input is. My friend forked it and extracts and lists any example data so you can click to load that example into those fields (my idea!). I tried it out and it's a very nice way to learn/explore a new API, especially testing edge cases where the docs are ambiguous. It really hits a sweet spot when you have documentation browsing, live execution and example data. I think creating a similar interface combining docstrings, the repl and example data from test fixtures would be a nice tool to have (I find doctests to be one of those things that are better in theory than in practice as they get too long and maintenance is annoying, although perhaps a more literate style in your source code would change that).
- john2x 13y agoYou would think that being most functions being pure, that these types of docsctrings would be more common (or standard, even).
- urlwolf 13y agoThis is exactly what R does. It's a huge timesaver. Best. docs. ever.