-
-
Notifications
You must be signed in to change notification settings - Fork 5
Establish convention for docstrings #133
Comments
There is the beginning of a representative example/template in the |
I will adapt my doc following Ryan's drafted template for now (it seems more adapted to what we do). Previously I was trying to follow the imutils/read_nii.m example because @po09i told me that it was the best documented so far. It would indeed be great to have an exhaustive convention ! |
Currently, the
is there a reason for having chosen this markdown? @rtopfer @po09i ? |
So far, the following template has been used. |
Apart from highlighting and linking to function names, I don't think the printed So far it's just trial-and-error, experimenting with that looks decent
|
I should add: The particular Markdown formatting is indeed informed by MATLAB's Markup rules, which is very similar to Markdown but there are discrepancies. For now, their Markup only seems to apply to Live scripts/functions, but I'd assume that MATLAB will eventually support Markup rendering within their own |
right. my current strategy is the following:
EDIT:
that is also my assumption, so sticking to the "browser" rendering syntax seems wise |
For now, the |
Re: Linking to references at the end of the documentation header, I found a hack yesterday worth noting + probably worth including in a template: MATLAB automatically adds the links when function/script/class entries are provided in a list where the line begins with "See also", e.g.
Ideally, this reference section should work with local links to help entries while running MATLAB and weblinks: After considerable trial and error I realised that by adding spaces between the sq. brackets both forms work, e.g
When displayed in the MATLAB terminal, you can click on Ultimately we would still want a parsing scheme for links in the autodoc process (e.g. to add/validate relative links for the Mkdocs build) but that will be a bigger undertaking. |
A few trials & errors: Header at the beginning of the fileThe following:
will look nice on the browser (see below): but will render a truncated doc this 'help':
So, it should be avoided Header for functionthe traditional matlab's:
will unfortunately not render in the browser. So a reasonable alternative is the following (notice the space between "%%" and "dicom_to_nifti"):
Matlab hyperlinksUnfortunately, @rtopfer's suggestion will not render in the browser: |
I thought maybe you meant in the webbrowser, eg. github, but this still works for me? |
Ah I see... If the latter will ultimately display the rendered HTML there could be a step added in the doc process remove the inner-bracket spaces Granted, it might not be worth trying to accommodate this very hacky hack, I just wanted to avoid having to repeat references, e.g. a section for normal weblinks followed by the usual |
I don't have a strong opinion either way but Re: SYNTAX and DESCRIPTION sections, while it would be useful to include the sections explicitly in a template for consistency + as a reminder to include them in a specific order, I find they're rather redundant: it's pretty obvious what the sections are without the added text, which is probably why MATLAB doesn't display section headers in the printed |
After struggling with Matlab's markup for rendering in the "new doc" (2nd option in this comment), I realize there are intrinsic incompatibility that makes this plan impossible. So, my updated strategy is the following:
|
Following up on the plan above, these are the exceptions/compromises to be made:
|
I have not worked on helpDocMd enough to know how feasible adding a new formatting output is as it was designed with markdown output from the beginning. Hopefully this can easily be done as it seems a really good idea. What do you think @rtopfer |
The motivation/context isn't entirely clear to me. Is the idea simply to have .html documentation for viewing internally within the Matlab browser? What would the advantage to using Re: tabling inputs and outputs, i find Markdown tables a bit easier to work with and inherently more readable than html tables. Though I don't think md tables support multi-line entries for a single cell, I don't think that's such a bad thing as it naturally encourages brevity (e.g. use a concise description in the table, and include a subsequent NOTES or ETC section w/extra details when necessary). We could, for instance, incorporate the text table into the doc template, and then parse it + reformat it to html for the matlab browser display. Matlab has the advantage of having some introspection tools built-in, so that helps autogenerate some doc content, but in terms of parsing/reformatting (or file management, for that matter) it would probably be much easier to do some of this in a different environment/language (e.g. sed, awk, perl). (Sidenote: this could be entirely specific to me, but it's rare that I ever use the matlab browser for viewing documentation: if the terminal |
yes, indeed.
the advantages I see with
are you referring to matlab's markdown tables? do you have an example? i really like html table outputs, each argument appears very clearly, and we can use columns for: name, type, description, e.g. here
not sure i understand what you have in mind. The "NOTES" and "ETC" would not be part of the "INPUTS", right? (therefore, would not be included in the tables). To make it clear: i was suggesting the use of tables only for input arguments (section "INPUTS")
hum... from what i've seen from the HelpDocMd, i feel we are very close from achieving this. You already parse everything. The only bit missing is support for another output format. But i admit i haven't dig deep into the code.
ok, well. We don't absolutely need to bother with a matlab doc. TBH, i'd rather not, given how poorly-developed their auto-doc environment is, and how fast it evolves across matlab releases, with minimum concerns for cross-compatibility. I started exploring this path, having in mind a "proper matlab toolbox", with all the associated features. But i am certainly not married to this idea. And at this point, we definitely have other priorities. So let's revisit this idea later, and for now we can focus on fixing the remaining issues on HelpDocMd, and especially agreeing on a header for .m files. |
👍 just to underline my previous suggestion "print the current class .md output to .m files and call
I mean like this which then renders on the site like
It doesn't really parse anything 😬 e.g. I initially spent quite a bit of time trying to parse Matlab's suggested html format for links before getting frustrated and realising the standard
👍 |
ah! indeed. Now i understand why there are all those funky characters in the header. Well in that case, since we are "close" to a nice solution, let's not spend too much time developing a parser. That could be a summer intern CS project. On the other hand, we could still tweak the format of the fields using simple solution, as discussed here. ok, so let's move on with the convention. My only strong opinion is about how we display input arguments. In this example, only the "option" flag is displayed in a table. I would like all input arguments to be displayed in a table. For struct, we could refer to a table below. Example: INPUTS:
|
Context
Python's autodoc tools such as sphinx parse the docstrings of functions/classes to generate API docs for convenient use. Importantly, things such as input arguments, output arguments, example usage, follow a given convention, such that the generate doc is consistent.
An example of convention for python is the Google docstring, displayed here for convenience:
While there seem to be less consensus for docstrings convention in Matlab, I believe we should still try to impose some rules, so that the doc (via matlab's help) and generated doc (via the HelpDocMd repos) look reasonably good.
Potential solutions
Googling around on the Matlab website, I've come across this documented function, which does look quite nice, in that: description, input arguments are parsed out and displayed.
Couldn't we come up with something similar?
Once we agreed on a convention, it should be documented under the contributing doc
Things to consider
Useful links
From Mathworks:
From external contributers:
The text was updated successfully, but these errors were encountered: