Repository navigation
Recommend Google as the docstring format - #42
thejcannon wants to merge 6 commits into
Conversation
|
Since this changes the Coding Conventions, I'll @-mention the appropriate NI engineers. @alejandro5042 |
mshafer-NI
left a comment
There was a problem hiding this comment.
I'm good with this rationale.
Co-authored-by: mshafer-NI <matthew.shafer@ni.com>
|
|
||
| def __init__(self, *args, **kwargs): | ||
| """Construct the click.Group with the config option.""" | ||
| """Constructs the click.Group with the config option.""" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Yeah, it's gonna be all-or-nothing. 😄 Anything in the middle would just be confusing...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Sounds good to me. I also buy the developer versus user argument. I've never heard that before but it makes sense.
There was a problem hiding this comment.
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).
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.""" |
There was a problem hiding this comment.
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.
|
This will fail PR due to what appears to be a bug in |
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