-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
API comment conventions #505
API comment conventions #505
Conversation
Might be worth adding conventions for code examples as well. Should "boilerplate" code be hidden with I've also been using |
This is an argument I had before and lost. I feel strongly that it should be |
This is a good question, but I don't think there's a consensus yet. |
If we go the |
|
||
# Detailed design | ||
|
||
There are a number of indivudal guidelines: |
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.
s/indivudal/individual/
FWIW, I don't remember you explicitly losing: it was just the overwhelming convention at the time to use |
Rustdoc is able to test all Rust examples embedded inside of documentation, so | ||
it's important to mark what is not Rust so your tests don't fail. | ||
|
||
References and citation should be linked inline. Prefer |
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 feel that it is somewhat important to do a proper citation for academic papers, since the link may die (or be paywalled or whatever) so having the author/title information allows people to track it down.
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.
But aren't there a few different 'proper citations'? I'll admit that I'm a bit unfamilliar.
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.
Why is this even a rule?
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.
@steveklabnik sure, there's various ways of doing a 'proper' citation (I don't even know what they are/how to write them by hand; I just use whatever BibTeX spits out), but that doesn't mean we should just give up on a long form entirely. :)
I guess we could chose one of the formal specifications, but it seems extremely low-priority since we don't cite things particularly often.
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.
As long as you have the title, authors, and year, any format is OK, but having those things is standard academically and makes things easy to find.
Is there ever a time where we have said "use block comments?" The only person I have seen in support of them was @nikomatsakis, but if they are not recommended, then should we remove them from the language? It would simplify the comment story, and if there is significant want for it, it can be re-added in a backwards compatible manner. I could write up the RFC and implement it (maybe id need some help though...) |
I'm not sure about the utility of block doc comments, but basic |
Any editor in popular use has some sort of |
Block comments are also the only option if you want to cut out the middle of a line. |
Is that used enough to matter? Do you think it may be a good idea to put something up on discourse and maybe see what people think? I have never seen block comments be recommended, so it may be good to remove them. Also i hate the fact that |
I didn't know that. Notepad++ does but it uses block comments to do it...it might be using C++ rules though...not sure. Does Gedit & Vim? Vim probably can because it can do anything. I'll have to check next time I can. playpen doesn't seem to. Useful for debugging. Just not recommended to push into commits. Also doesn't rely on that block comment feature being there. |
Fair enough. I had submitted a patch to turn them all into |
I would support removing block comments, but let's please keep that out of this RFC. Removing them would be another, it's just noise here. |
This should perhaps be merged into the Rust Guideline. |
* Panics | ||
* Failure | ||
|
||
Even if you only include one example, use the plural form: "Examples" rather |
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.
This is really lame. If there's a single example (as is true in the vast majority of cases), the singular form should be used because that's how English works.
Tooling can use the regex Examples?
instead of Examples
. If the tool authors can't figure this out, we need better tool authors.
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.
@cgaebel you're getting quite aggressive, could I ask you to tone it down a little?
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.
+1 for singular "example"
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.
An additional reason to use 'Examples' is becaue there should be more than one in most cases, and even if there is only one and they change later, the only part of the diff that changes is the addition of the example itself.
So, I wonder @steveklabnik why you recommend writing comments inline? It seems like it's strictly less readable. However, I do wonder if we're talking about the same thing. To be clear, I prefer:
or
to
|
@nikomatsakis I'm fine with either of those. I've historically just done number one, that part is kind of a straw-man. |
I prefer inline links too, and I dont believe them to be strictly more readable, with citation style, you need to go to the bottom, see where it links to then scroll back up. Thats just an example, like all stylistic choices, pick one. I consider inline easier to write, so ill +1 for that subjective reason. |
@sinistersnare the rendered docs display the same, and one often puts citation-style just after the paragraph/section where they are used (at least, I do). |
You don’t need to put “citation” links at the bottom. I tend to leave them just after paragraph where I used it. I dislike inline links as they don’t always fit into a line and you get something ugly like: This is research on the [best languages]
(http://example.com/unbearably/long/path/to/the/paper.pdf?with=true&alot=indeed&ofparams&authorised=✓)
I’ve conducted. Be sure to read that. |
|
||
All doc comments, including the summary line, should begin with a capital | ||
letter and end with a period, question mark, or exclamation point. Prefer full | ||
sentences to fragments. |
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.
This seems a little english-centric for generic guidelines - how about "All doc comments, ..., should be properly punctuated, full sentences."
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.
All documentation is standardized on American English, with regards to spelling, grammar, and punctuation conventions.
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.
Yep, I think that is wrong too.
Function / method documentation — do we have a good style suggestion for how to write parameter and return value documentation? Good documentation should contain all of this I guess: brief summary, documented parameters and return type, panic cases (if any), and an example. About emphasis in function / method documentation: In my own code I have started to mark up parameter names (foo) and values (None, true) and class names (Graph<N, E>) in boldface. Parameters and classes are bold in rustdoc's markup, and the gray box around |
Actually, rustdoc should be made to link to these automatically or at least semi-automatically with annotations (such as the aforementioned graves). |
Should we prefer I think we should use
|
…alexcrichton Hi! I added some examples to some stable SliceExt methods that didn't have any. I'm looking forward to feedback and I'm happy to change anything-- it looks like the doc conventions are still a bit in flux, based on the discussions going on in [rfc 505](rust-lang/rfcs#505). I was most unsure about examples for methods that return iterators over slices... I wanted to use asserts on the result of calling `.next()` like in [this permutations example](https://github.com/carols10cents/rust/blob/804c1446b3b0afd84851339d8ee2be1dca8f7713/src/libcollections/slice.rs#L608-L617), but then it gets all cluttered up with lifetime stuff... so I went with iterating and printing and mentioning what the expected printed output is like in [this chunks example](https://github.com/carols10cents/rust/blob/804c1446b3b0afd84851339d8ee2be1dca8f7713/src/libcollections/slice.rs#L297-L304)... any ideas for the best ways to do this are appreciated. Thank you! ❤️
…alexcrichton Hi! I added some examples to some SliceExt methods that didn't have any. I'm looking forward to feedback and I'm happy to change anything-- it looks like the doc conventions are still a bit in flux, based on the discussions going on in [rfc 505](rust-lang/rfcs#505). I was most unsure about examples for methods that return iterators over slices... I wanted to use asserts on the result of calling `.next()` like in [this permutations example](https://github.com/carols10cents/rust/blob/804c1446b3b0afd84851339d8ee2be1dca8f7713/src/libcollections/slice.rs#L608-L617), but then it gets all cluttered up with lifetime stuff... so I went with iterating and printing and mentioning what the expected printed output is like in [this chunks example](https://github.com/carols10cents/rust/blob/804c1446b3b0afd84851339d8ee2be1dca8f7713/src/libcollections/slice.rs#L297-L304)... any ideas for the best ways to do this are appreciated. Thank you! ❤️
We don't currently do this much in the standard library, so I'm leaving it off for now. If
My understanding is that |
@nikomatsakis updated regarding 'citation style', I was confused as to what exactly you were talking about originally. |
Whew! It's time to get this RFC shipped. Thank you all for your comments a while back, and sorry I couldn't get to them sooner. I think this is in a pretty decent place now. It doesn't cover every single possibility, but I think it's a base we can work from. I would prefer to ship a smaller RFC that we can all agree on and then add things than argue endlessly about every last convention. :) |
Wait what? That can't be right. == returns a bool, and assert acts on a bool... |
Searching on the issue tracker for that is likely to be hard, I think it was @alexcrichton ? |
I think you refer to the fact that we can't special-case the Anyway, maybe this is an ex-issue? assert_eq! is cryptic but if we use it everywhere, users of documentation are forced to learn it. Ideally for me, there should be a clearer, prettier way to write documentation examples that simultaneously demonstrate a fact while making it testable automatically. |
On IRC, it was mentioned that it was about error messages, basically |
Yeah. I hope in the future we'll just have some other more awesome (and easier to read) way to write testable examples without using either of the two assert macros. |
We (the core team) have decided to merge this RFC so that we at least have some official style guidelines to use. To a large extent, this RFC simply formalizes existing practice. We can always revise if/as needed. This is the first "style" RFC, so it's expected that we'll want to perhaps integrate these suggestions into a broader style guide when we decide to tackle that topic. |
Rendered
I'm mostly trying to codify what we already have consensus on, rather than address every possible question. I can forsee this kind of RFC getting very bogged down in a number of different details, and we can always add more things in a future RFC.