Skip to content

Best practices for XML doc comments #2202

Description

@jnm2

(Edit: I've replaced 'coding standards' with 'best practices' because I meant something very different by it than the way it is intended to be used in the context of https://github.com/nunit/docs/wiki/Coding-Standards.)

I've noticed our XML documentation is a little inconsistent. Some sentences have missing periods and some single nouns with an adjective or two do have periods. Leaving periods off of sentences is, as a starting point, neither generally a professional style nor a standard in the .NET BCL.

I'd vote for requiring the period no matter the length of the description and in scenarios where it looks awkward, rather than dropping the period, add a couple more words to make a sentence.

I think this is one of the most important coding standards best practices to have. It's user-facing and extremely visible. It reflects on the quality of NUnit as a whole. Whatever we settle on, could we put it in https://github.com/nunit/docs/wiki/Coding-Standards a coding best practices doc? I can do that and a pass over the codebase.

/cc @nunit/framework-team


My bucket list for other XML documentation coding standards best practices (draft):

  • Consider <paramref name="parameterName"/>, <see cref="TypeOrMember"/> and sometimes even <see langword="null"/> when possible.
    This creates links in the Object Browser and intellisense and colorizes intellisense. The compiler checks the validity of the names and overloads and you can refactor with confidence.

  • Add a <summary> tag for each type and member. However, prefer to give each type and member a really communicative name. If those names end up covering all the user could need to know, remove the <summary> tag to avoid super redundant documentation. Otherwise, add relevant details.

  • Add a <param> tag for each parameter describing what effect it has (rather than what it is). However, prefer to give each parameter a really communicative name. If those names end up covering all the user could need to know about all the parameters, remove all the <param> tags to avoid super redundant documentation. Otherwise, add relevant details to each <param> to the extent possible.

  • Don't spend any time on the <remarks> or <returns> tags since the contents are not typically seen. Important details should all be in the <summary>. If the IDE auto-inserts them, just remove them.

  • Don't leave any empty tags. Either remove them or fill them out. This includes the compiler's all-or-none <param> tag enforcement.

  • Consider documenting thrown exceptions with the <exception> tag.
    This can really get the consumer up to speed on things that aren't immediately obvious from the method signature.
    Sadly intellisense will only show the exception types thrown, not the message, so for important exceptions it's good to also include it in the summary:

    /// <summary>
    /// Does foo. If <see cref="OtherProperty"/> is not set, throws <see cref="InvalidOperationException"/>.
    /// </summary>
    /// <exception cref="InvalidOperationException">Thrown when <see cref="OtherProperty"/> is not set.</exception>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions