open-sorcerers / madlib

Madlib: a compile-to-JS language written in Haskell, designed to make writing code a delight
https://github.com/madlib-lang/madlib
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Solve the problem of accurate documentation #28

Open brekk opened 3 years ago

brekk commented 3 years ago
  1. Code gets written
  2. Documentation gets written
  3. Iterate
  4. See that the documentation isn't in sync with the code?

How do we solve this?

Random thoughts from the dome:

brekk commented 3 years ago

Or maybe you have something closer to a C-style header file, and that human-managed file has syntax for how to auto-generate an example / documentation.

brekk commented 3 years ago

Some examples from Julia + D:

  1. Julia use a separate syntax entirely
  2. D uses inline unittests
brekk commented 3 years ago

Proposed syntax for examples syntax:

add :: Number -> Number -> Number
add = (a, b) => (a + b)
add examples (
  5    |> ???(2, 3) -- Positive Numbers can be added together
  0    |> ???(-100, 100) -- Negative Numbers can be added together
  -100 |> ???(-100, 0) -- Zero is a valid Number
  1.23 |> ???(1, 0.23) -- Floating point Numbers are valid
)
aboeglin commented 3 years ago

As said on slack, I like the proposal very much. I think that should maybe be an inline version of a longer form that can allow easier setup of more complex things to test ? I'm thinking things like setting up a Wish that mimic an API or read some fixtures or something among these lines.

aboeglin commented 3 years ago

Also, already talked about that but I'm not sure where we stopped, I think we should give the option to write examples in a separate file. Maybe we can make it a convention that the name of the file need to match but extension differs like .h in C ? Something like:

Well, I find examples a bit long for an extension. I'd propose mex for Madlib EXamples.