Skip to content

Recommend Google as the docstring format - #42

Closed
thejcannon wants to merge 6 commits into
ni:mainfrom
thejcannon:docstring-format
Closed

thejcannon wants to merge 6 commits into
ni:mainfrom
thejcannon:docstring-format

Conversation

@thejcannon

@thejcannon thejcannon commented Jan 8, 2021 •

Copy link
Copy Markdown
Contributor

Having any documentation is better than no documentation. Likewise following a format is better than not. However choosing a format can be intractable.

We chose Google style because the majority of people preferred it.

Since type hints exist (and we will be recommending their usage) the type information format of either doesn't concern me much.

NOTE: This PR started off recommending sphinx format

@thejcannon
thejcannon requested a review from neilvana as a code owner January 8, 2021 19:48
@github-actions

github-actions Bot commented Jan 8, 2021

Copy link
Copy Markdown
Contributor

Since this changes the Coding Conventions, I'll @-mention the appropriate NI engineers.

@alejandro5042
@alexweav
@DavidCurtiss
@irwand
@jryckman
@kcuzner
@mshafer-NI
@neilvana
@nethrasuresh
@pakdev
@rick-morrow
@rtzoeller
@sbethur
@stick152
@thejcannon

@mshafer-NI mshafer-NI left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this rationale.

Comment thread docs/Coding-Conventions.md Resolved
Co-authored-by: mshafer-NI <matthew.shafer@ni.com>
@DavidCurtiss

Copy link
Copy Markdown

You can use RST syntax in Google-style docstrings, too (e.g. here, generating this).
And I don't mind the indentation -- it helps readability.

Comment thread docs/Coding-Conventions.md Resolved
Base automatically changed from master to main January 11, 2021 20:09
@thejcannon thejcannon changed the title Recommend sphinx as the docstring format Recommend Google as the docstring format Jan 19, 2021

def __init__(self, *args, **kwargs):
"""Construct the click.Group with the config option."""
"""Constructs the click.Group with the config option."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. I like the styling of the Google docstrings, but I've tended to prefer imperative method summaries, to harmonize with the rest of the Python community. But I can live with descriptive instead, if we have to go whole-hog on one standard or the other. One advantage of descriptive-style is that it would match our C# docstring conventions, so that's good, at least.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well shit, I prefer the other style.. Must we adopt this as part of Google docstring style?
I suppose if we subscribe to google docstring, we should just follow that and keep it simple.. but.. bah!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's gonna be all-or-nothing. 😄 Anything in the middle would just be confusing...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bummer :( ..anyway not a big deal.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's kind of a big deal. Now our conventions violate PEP-0257. If this difference was highlighted pre-voting I would have changed from ambivalent to Sphinx.

@neilvana neilvana Jan 21, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish the Python community had a readable, more consistent, standard. I like the overall readability of Google Style because it looks like it was written for a human and not a computer. The Sphinx style seems written for a parser not a human. I prefer Google Style for the same reason I prefer yaml or toml over XML.

But why did Google decide to deviate from PEP-257 in this way? --Neil wrings his hands-- Did they want to match other languages at Google? Were they just trying to be difficult? I don't think I even noticed this deviation when reading the style the first time (so good catch) and have generally preferred imperative mood since it usually is shorter and matches convention in Git commits.

(It's minor, but I'm also personally not a fan of mixing the imperative style description which can be seen as "first-party" with the "third-party" "Args", "Returns", "Raises", etc...)

I just interpret those as plurals nouns rather than descriptive verbs since a function has multiple arguments, can return multiple values, and can raise more than one thing. It's a little of a stretch but makes me feel better :-)

My personal preference would be to adopt Google Style and PEP-257 and prefer PEP-257 where they conflict (i.e. use imperative mood).

As a side curiosity do we have a mood standard among any other languages at NI?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NI's C# code uses declarative style, though it's not explicitly called out in the style guide (though there are examples there that are declarative).

@thejcannon thejcannon Jan 22, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsurprisingly, Google's developer documentation style guide states:

When you're writing reference documentation for a method, phrase the main method description in terms of what the method does (gets, lists, creates, searches), rather than what the developer would use it to do (get, list, create, search).

I've also read a handful of posts from various people online (language-agnostic) basically saying "client documentation uses descriptive. Developer documentation (I.e. comments) uses imperative". I think this makes the most sense as it fits with the context of what's being described and to whom.

Ultimately, I think I'm inclined to leave it as "We follow Google's guide." which would mean advocating for descriptive style across the company. However also calling out, much like which guide to follow that being consistent is ultimately the important thing. The tooling currently doesn't enforce any verb-mood, and I'll switch it back to simply enforce all conventions (minus verb mood).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. I also buy the developer versus user argument. I've never heard that before but it makes sense.

@alejandro5042 alejandro5042 Jan 22, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I love their explanation. Talk in terms of what the method can do for the user (gets the thing), instead of what the program will do if you use it (get the thing).

Comment thread docs/Coding-Conventions.md Resolved
Co-authored-by: Ryan Zoeller <Ryan.Zoeller@ni.com>

def __init__(self, *args, **kwargs):
"""Construct the click.Group with the config option."""
"""Constructs the click.Group with the config option."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example provided by the Google conventions doc we link to states:

A docstring should give enough information to write a call to the function without reading the function’s code. The docstring should be descriptive-style ("""Fetches rows from a Bigtable.""") rather than imperative-style ("""Fetch rows from a Bigtable."""),

The difference is: Fetches vs. Fetch

I'd be happy with either, and neither IMHO negates using the Google style for formatting your docs.

I'm wondering: how important is this distinction? I guarantee you I will never think about this again after this PR 😛 Persuading devs to slow down and document their code is hard enough even before we become grammar police and enforce verb tense to use 😄 I'd rather tell devs "please document! and here's how it should look" than "please learn the difference between imperative and descriptive and keep that in mind when you document." I'd rather advocate active verb tense over passive.

@thejcannon

Copy link
Copy Markdown
Contributor Author

This will fail PR due to what appears to be a bug in pydocstyle. I made an issue here: PyCQA/pydocstyle#523

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.