Skip to content
Permalink
Browse files

first draft of doc guideline RFC

  • Loading branch information...
steveklabnik committed Sep 17, 2014
1 parent bfdcd21 commit a2c5c7afc8fa4d2d4682721611669e7acdd66883
Showing with 148 additions and 0 deletions.
  1. +148 −0 active/0000-documentation-guidelines.md
@@ -0,0 +1,148 @@
- Start Date: 2014-09-17
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)

# Summary

This is a _conventions_ RFC for formalizing the basic conventions around
documenting Rust code.

# Motivation

Documentation is an extremely important part of any project. It's important
that we have consistency in our documentation.

For the most part, the RFC proposes guidelines that are already followed today,
but it tries to motivate and clarify them.

# Detailed design

Full and complete documentation for any Rust project should include the following:

1. A high-level, informal overview (a 'guide')
2. In-depth, cross-cutting topic-level documentation (other 'guides')
3. API documentation

`rustdoc` is able to produce all three kinds of documentation, and should be used
for all Rust documentation.

First, we'll talk about each type of documentation individually, and then cover
styles that are common across all three kinds of documentation.

## The Guide

A "guide" is an entry point into your project. As such, it should be written at
a high level, and not dig too deep into the details. To learn more, a reader
can consult the other documentation.

A `README.md` file often serves as a guide for many Rust projects, but this
role can also be served by a separate document.

The guide should cover:

* Installing your project.
* If it is a library, example lines to place in your `Cargo.toml`.
* An overview of features your project includes.
* Basic usage of your project.

After reading a guide, your user should have a basic grasp on what your library
is, what it does, and how to use it.

Your guide should point users to other documentation for more details where
appropriate.

## Guides

Depending on your project's size, additional guides may be appropriate.
Individual guides work well for cross-cutting concerns in your library. Any
concepts which span multiple modules are good fit for a guide.

## API documentation

Good API documentation is key for using your library. Here are guidelines when
writing API documentation:

Avoid block comments. Use line comments instead:

```
// Wait for the main task to return, and set the process error code

This comment has been minimized.

@P1start

P1start Sep 18, 2014

This example (and the one below) should be written in third person singular present indicative, as advised below.

// appropriately.
```

Instead of:

```
/*
* Wait for the main task to return, and set the process error code
* appropriately.
*/
```

Only use inner doc comments `//!` to write crate and module-level

This comment has been minimized.

@nathantypanski

nathantypanski Sep 17, 2014

Perhaps there should be some explanation of why to use inner doc comments for this, rather than just saying it.

documentation, nothing else.

Within doc comments, use [Markdown](https://en.wikipedia.org/wiki/Markdown)
to format your documentation.

Use top level headings `#` to indicate sections within your comment. Common
headings include 'Arguments,' 'Examples,' and 'Failure'.

This comment has been minimized.

@quantheory

quantheory Nov 23, 2014

This line mixes punctuation styles. Either the commas should be outside the quotation marks, or the period should be inside, whichever is consistent with the recommendation below.


The first line in any doc comment should be a single-line short sentence
providing a summary of the code. This line is used as a short summary
description throughout Rustdoc's output, so it's a good idea to keep it short.

This comment has been minimized.

@nathantypanski

nathantypanski Sep 17, 2014

In general, I think the guidelines should have a more formal tone, so using "it is" instead of "it's" here is appropriate.

Edit: There are more contractions in this doc, and it looks like I originally wrote some of them, but I'm pretty sure that was a mistake and the guidelines shouldn't have them.

This comment has been minimized.

@quantheory

quantheory Nov 23, 2014

I disagree. There are some obvious words to avoid (e.g. "ain't"), but avoiding contractions completely makes a document stilted and harder to read. Unless you are writing something extremely formal or ceremonial (e.g. a wedding invitation), I would not go through and replace these.

The U.S. Federal Government even advocates some use of contractions in safety guidelines and legal documents.


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.

The summary line should be written in [third person singular present
indicative](http://en.wikipedia.org/wiki/English_verbs#Third_person_singular_present)
form. Basically, this means write "Returns" instead of "Return".

## Common Style Guidelines

All documentation is standardized on American English.

This comment has been minimized.

@quantheory

quantheory Nov 23, 2014

I noticed a comment you made in the Ownership guide pull request about punctuation. I wanted to make some points:

  1. You may want to explicitly state that both American spelling and punctuation are preferred (assuming that that is what you meant).
  2. Simply stating that documentation should use American English does not fully clarify whether or not one should put periods and commas inside quotation marks, for two reasons:
    1. There is no longer a de facto consensus on this point in American publications. In technical reference material that quotes non-English text, there is an emerging consensus in favor of logical punctuation, even when American spelling is used. Wikipedia articles in American English, GNU documentation, Python's PEPs, some printed technical references, and a few newspapers use American spelling with logical punctuation.

    2. The major American style guides still have a consensus on periods and commas inside quotes (specifically, AP, APA, MLA, and CMOS). However, this consensus is rather weak with respect to sentences quoting computer output or file names. For instance, it seems that this is technically allowed by The Chicago Manual of Style:

      The trait actually expressed by the organism is called its "phenotype," so the field containing this data is named "Phenotype".
      

      This is a bit strange, so in some cases CMOS does add the disclaimer that one should really just do whatever makes the text clear.

My preference would be to use logical punctuation, since it seems to be much more common for code documentation. But either way, the quotation style should be pointed out explicitly.

This comment has been minimized.

@P1start

P1start Nov 23, 2014

Whenever I read parts of the Guide I find that I often get rather distracted by the fact that punctuation after a quoted section was included inside the quotation marks. Perhaps it’s because I don’t use American English, but I found it a very strange convention that I haven’t seen (or at least noticed) very much elsewhere. It makes sense to me for something logical like a programming language to adopt the more logical punctuation style.

Speaking of punctuation, I wonder if we should specify what kind of quotes to use (single or double) and what style of quotes (curly (“”) or straight (")). Most keyboard layouts don’t have curly quotes, so maybe that’s not an option.

This comment has been minimized.

@quantheory

quantheory Nov 23, 2014

I think it's asking too much to require characters that aren't on most developers' keyboards, so I would vote against that. I lean toward double quotes because I'm an American (we only use single quotation marks for nested quotes), and because they are required for C strings.

I don't have a strong opinion on this, but we should probably be consistent. I notice that this document actually uses both.


Use graves (\`) to denote a code fragment within a sentence.

Use triple graves (\`\`\`) to write longer examples, like this:

This code does something cool.

```
let x = foo();
x.bar();
```

When appropriate, make use of Rustdoc's modifiers. By default, triple graves will
make the assumption that Rust code is contained within. For anything that's not
Rust code, annotate it with the proper name.

```ruby
puts "Hello"
````

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

[some paper](http://www.foo.edu/something.pdf)

to

some paper[1]

1: http://www.foo.edu/something.pdf

This comment has been minimized.

@nathantypanski

nathantypanski Sep 17, 2014

You probably meant to have four spaces before these lines.


# Drawbacks

None.

# Alternatives

Not having documentation guidelines.

# Unresolved questions

None.

0 comments on commit a2c5c7a

Please sign in to comment.
You can’t perform that action at this time.