I’ve been thinking about how Julia’s documentation system could work, particularly in terms of editor support. There are probably already ideas floating around about how to do this, but I’ll throw in mine:
Doc strings are written as triple-quoted strings placed immediately before the relevant function/module. They are written as markdown, so that they can be richly displayed in interactive environments (Light Table, IJulia) and in the terminal (e.g. by using bold, underline and colours) when help(f) or ?f is called.
What this would mean is that inline docs can be displayed richly as you edit code. For example, you open up a .jl file in Light Table and it looks like this, with the docs automatically rendered:
module TestDoc
"""
# Docs Test
This text will be displayed as (a subset of) markdown as it is edited.
Fitting the text to a reasonable width is taken care of, so you let the
docs flow *without* worrying about **formatting**.
You can use code blocks too, of course:
2+2 = 4
"""
"""
Square a number.
square(2) = 4
"""
function square(x) # A regular comment
return x*x #| A formatted one.
end
end
(And of course, if you open up in a normal editor it’s just plain text – but luckily plain markdown looks pretty good anyway)
This would be fairly simply implemented in Light Table, at least. Another way to signify docs might be to have a line of comments rather than strings, marked out as docs like this:
#| # Docs Test
#| This text will blah…
I’ll probably implement something like this in LT anyway, but it’s so much better if it’s directly supported by the language.
Any thoughts on this?