-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support brief and extended docs (closes #25930) #34226
Conversation
d85473d
to
4ec6194
Compare
I've added the docs and NEWS, so this is ready for any feedback. |
A limitation of this feature is that REPL users still can't read those lengthy extended docstrings. I imagine some paging utils (e.g., |
I think that's mostly an orthogonal PR. Currently help is displayed via the |
Oh, what I intended to say is once there was a pager, the feature proposed in this PR would be more or less useless. IPython uses |
That's an idea worth exploring. Would we use the pager to handle multiple methods? I.e., if you do A downside of the pager is that it might be slightly irritating to have to exit the pager each time you do
We already have |
I think that makes reading docstrings easier.
Is something like |
Currently that retrieves the documentation for |
A level-1 header "Extended help" indicates that the content that follows requires `??foo` rather than just `?foo`.
4ec6194
to
4916589
Compare
If someone comes along later and adds pager support, will we regret anything here? I think the real issue is whether we're happy with Would be nice to get a code review, maybe @mortenpi? But if no one has time I'll merge this in the next few days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved all the functionality to the REPL. I agree, I think this makes more sense.
This is great! Some thoughts:
Doesn't have to be adressed in this PR, just some thoughts I had while trying it out. |
That was deliberate, in case there was a function with
I like that idea, but a cautionary note: help?> ?
search:
Welcome to Julia 1.3.2-pre.0. The full manual is available at
https://docs.julialang.org/
as well as many great tutorials and learning resources:
https://julialang.org/learning/
For help on a specific function or macro, type ? followed by its name, e.g.
?cos, or ?@time, and press enter. Type ; to enter shell mode, ] to enter
package mode. I'm a little uneasy giving this special meaning just because it happened to follow a case where there was extended help available.
I went with that suggestion, good idea.
Good idea, I've allowed all three.
I worry this is more subtle than it sounds. What happens when you hit Ctrl-C at the beginning of the line---does it drop back to non-extended help or the julia prompt? (If we just changed the prompt it would drop back to Julia mode.) What happens when you're paging back through your history, does it remember to access it in extended vs non-extended mode? Really I think the only way to do it right is to add a whole new REPL mode. By requiring the |
Yea, and I agree the current approach is less spammy.
But that is just a default fallback, you get the same from just "Enter" at the empty help prompt. |
Thanks for posting that fantastic article. I'm all in favor of formalizing this a bit more. In the context of the blog post, it seems that my vision of In the context of docstrings for individual methods (I'm specifically not talking about whole package ecosystems), the line between "tutorial" and "how to" often seems blurry. I think this is specifically because of the ethic that functions like those in Base should generally do one specific small thing, and so one or two examples pretty much shows you what you need to know. When functions start taking a dozen arguments, then "tutorial" and "how to" take different forms. |
Yes, docstrings tend to start with a terse reference section, and that's often all I want to see. Sometimes I look up the help for, say, For sure there's unlikely to be something recognizable as a full tutorial or how-to in a docstring. Those tend to need a bigger story which will thread together use of many different functions. Though I wonder whether there's some value in being able to extract the example sections from docstrings to insert into a tutorial in the main docs. It might be tricky because it increases the coupling between the separate docs and the docstrings, but it would make for a super consistent set of examples between related functions. Anyway, so you're imagining that we could have subsections under extended help? Something like the following perhaps?
Say we had all this structure; what could the system do with it by default to really brings a lot of value for users? |
The |
I really feel like "short" and "long" modes are all that anyone will remember. Need a quick refresher? Use |
I think it'd be better to keep the main focus of docstrings to API references and link materials of the other three quadrants just before |
Agreed; so far been unable to think of a compelling use for extra structure in the docstrings, at least from a REPL point of view. I'm starting to think that the simple answer is that docstrings should be reference documentation only. This is natural for their location interspersed with the source code, where developers only want to see a terse but accurate and complete description. Aha! And on this point, I finally know why the content of #33936 bothers me. It's tutorial content, but we don't have a place for tutorials.
Very true.
Great idea! If we could allow easy cross references from the docstrings to the tutorial and explanation sections of the manual, I think we would solve our problem. One thing I've worried about in the past was that the source code is not linked to the explanation sections of the Julia manual. So anyone who either
is missing out on a great deal of important content. |
I think linking tutorials etc. from the docstring somewhat helps the second kind of readers. Ideally we can use |
I feel like just the reference in the docstring is enough as that sits next to the source code. It doesn't need to be super convenient to access, but merely a reminder that there's more content to look for. (Personally I often read the source before looking at the docs, but I assume we don't need to optimize for this case :-) ) Baking in URLs isn't ideal as they refer to a particular hosting location. On that note: it would be cool if |
For docstrings, I totally agree. I was thinking more about lengthy inline comments that explain something about surrounding code blocks. It may be useful to link to a discussion/explanation section of the documentation. It would be certainly nice if this link is also re-locatable. But I think it's OK in this case because the audience of the inline comments is very narrow. (Alternatively it makes sense to use relative file paths.) |
Agreed. Actually I made an issue about this very thing a while ago, but it didn't generate much discussion and I kind of forgot about it #29527. |
Maybe we could have some way of indicating in a docstring which sections of the docstring should be included in the short versus long docs? |
Do you mean something like One option would be to extend the title convention: for example any heading starting with Another option would be to consider |
Yes, that's what I meant. It does seem like having them interspersed in the long version might be better and the convention of the name starting with "Extended" is pretty clear. |
I had completely missed this discussion. Very nice! Looking at changes that are needed to use this in DataFrames (JuliaData/DataFrames.jl#2250), I wonder whether we shouldn't treat content appearing after any heading as extended help. In DataFrames, 90% of the time the PR just adds |
A lot of docstrings look like this, I worry that without the example it will become much less clear. |
I agree, and even sometimes examples are part of the specification (but that might be a documentation bug...), e.g. in which order |
I disagree. The short description should be improved if it's not clear/detailed enough to explain the general behavior of the function without looking at examples (even if examples are great to help understanding). In the EDIT: More generally, I think we need to add precise guidelines to the manual regarding what should be in the short vs. extended help. People may have quite varied expectations and inconsistency risk making this feature counter-productive for users. |
English may be the common language for open-source packages, but I'd expect lots of in-house packages to have docstrings in other languages. So baking in a special meaning for the English phrase “Extended help” seems less than ideal. (Also, I prefer not to refer to documentation as “help”: to me “help” is what you offer to people who haven't read the documentation.) It would be nice to be able to start the extended docstring with arbitrary headings, such as “Details”, “Examples”, “Application hints”, “Further information”, “Gory details”, “Full specification”, “Background”, “Compatibility concerns”, “Performance tips”, etc. @nalimilan's suggestion to simply treat the first heading as the start of extended help sounds simple and practical. That convention works well e.g. for Wikipedia/Mediawiki, where the convention is that there should be a self-contained short lead section of the article before the first heading. If that cuts off examples, perhaps that's a good thing if it encourages authors to make the first section so clear that “Examples” sections really become what they should be: optional additional information. |
Your point is a good one but I disagree that we can suppress the current We might need some other syntactic idea here, but at the moment nothing comes to mind. |
Many Markdown applications allow the use of HTML tags in Markdown-formatted text, so HTML could be a source of suitable syntax for an invisible division marker. One good example is the “more tag” that WordPress uses to separate the introductory part of a blog post (which goes in the front page) from the rest of the full blog post:
or with an added continuation text:
That's a stylized SGML/HTML comment section. Other ideas from HTML/SGML syntax would be adding an element such as Incidentally, Github's Markdown renders these as
Also:
However, we can't have the docstring author insert an |
Demo:
I've checked that this doesn't seem to break Juno. I've not tested jupyter.