Visitar URL original
Add sections on comments and error messages in coding guide by namurphy · Pull Request #1660 · PlasmaPy/PlasmaPy · GitHub
Skip to content

Add sections on comments and error messages in coding guide - #1660

Merged
namurphy merged 16 commits into
PlasmaPy:mainfrom
namurphy:coding-guide-comments-errmsgs
Aug 11, 2022
Merged

namurphy merged 16 commits into
PlasmaPy:mainfrom
namurphy:coding-guide-comments-errmsgs

Conversation

@namurphy

@namurphy namurphy commented Aug 4, 2022 •

Copy link
Copy Markdown
Member

This PR adds sections to the coding guide on best practices for writing comments and error messages. This PR is possibly the last spinoff of #1305.

It might be worthwhile to briefly comment on LBYL vs. EAFP here. The LBYL approach allows us to produce better error messages, which are really important for a library...even though EAFP usually leads to cleaner code.

This PR has been brought to you by my desire to procrastinate washing dishes. 🍽️

@github-actions github-actions Bot added the docs PlasmaPy Docs at http://docs.plasmapy.org label Aug 4, 2022
@codecov

codecov Bot commented Aug 4, 2022 •

Copy link
Copy Markdown

Codecov Report

Merging #1660 (f101e34) into main (5a51592) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1660   +/-   ##
=======================================
  Coverage   97.23%   97.23%           
=======================================
  Files          84       84           
  Lines        8016     8016           
=======================================
  Hits         7794     7794           
  Misses        222      222           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@namurphy
namurphy marked this pull request as ready for review August 4, 2022 14:26
@namurphy
namurphy requested a review from a team August 4, 2022 16:15
@namurphy namurphy added the status: ready for review PRs that are ready for code review label Aug 4, 2022
@@ -279,39 +279,138 @@ to edit the pull request by changing the corresponding branch on your
PlasmaPy fork on GitHub. After a pull request is merged into the

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 coding guide is getting rather long. I'm thinking it might be time to add a ``.. contents:` to the top of the page. Thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressing it in #1662 for not only the coding guide, but also the other pages in the contributor guide.

Comment thread docs/contributing/code_guide.rst Resolved
Co-authored-by: Erik Everson <eteverson@gmail.com>

Suggestions on `how to write a git commit message
<https://cbea.ms/git-commit>`_:
Comments

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.

I wonder if establishing a "golden rule" would be useful here. Maybe even put it into an admonition. I personally get lost in a list of guide points, so having a golden rule to check against is what I find most useful. The golden rule I tend to tell people goes something like:

Your code should read like a book, that is the full meaning of your functionality should be attainable by reading the code. A comment is only used when code itself can not communicate the full detailed meaning.

I'm sure there's a better way of phrasing this, but I think it covers all the points you say below. I think pairing the "golden rule" with your points as examples would be overall more effective.

Thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea! I'll add something like this in, likely after I get back from visiting family.

Comment thread docs/contributing/code_guide.rst Outdated
Comment on lines +318 to +320
* When possible, include enough contextual information that the comment
will make sense even if it is displaced from the code it was
originally describing.

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.

I'm not sure how to visualize this point. Is there a good example. I think it's a little confusing without more context. (Sorry, I couldn't resist saying that last bit.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I decided to delete this point since there is already another one that says to provide context.

Comment thread docs/contributing/code_guide.rst Resolved

* When updating code, be sure to update the comments too!

* When a comment is used as the header for a section of code, consider

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.

You're going to make me rage quit with this point. 😂 I'd like to see some kind of comment in here that there's a "subjective" balancing act with the extract function refactoring pattern. Overall it's good, but when used on a too fine of a scale it can significantly reduce code readability.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's a good point! This is a good place to put in a tradeoff analysis and how there are different factors we need to balance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in a discussion on this below.

Comment on lines +382 to +385
Error messages are a vital but underappreciated form of documentation.
A good error message can help someone pinpoint the source of a problem
in seconds, while a cryptic or missing error message can lead to hours
of frustration.

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.

I had a sphinx error like this yesterday. It didn't even tell me what file the error was in. Ahhhh... 😤

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

YEP.

Comment thread docs/contributing/code_guide.rst Resolved
Co-authored-by: Erik Everson <eteverson@gmail.com>
Comment thread docs/contributing/code_guide.rst Resolved
Co-authored-by: Erik Everson <eteverson@gmail.com>
Comment thread docs/contributing/code_guide.rst Outdated
Comment on lines 415 to 416
* The exceptions raised by a method should be described in the
method's docstring. Documenting exceptions makes it easier for

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.

Do we have a doc guide rule on this? This is one of the most difficult parts of writing a docstring. And, I often find this part of the docstring is like a comment, always out of date.

@namurphy namurphy Aug 4, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hm...perhaps we could emulate the numpydoc section on this, and say that the Raises section should be used judiciously and only include non-obvious exceptions.

  • Do ↑
  • Update the doc guide section on this too

And, I often find this part of the docstring is like a comment, always out of date.

All too true...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated this, and moved it to the doc guide as a means of procrastinating packing.

@namurphy

namurphy commented Aug 4, 2022 •

Copy link
Copy Markdown
Member Author

So that I have it handy when I get back from vacation, the things from code review that I still need to address are...

  • Add in the golden rule

namurphy and others added 3 commits August 11, 2022 12:16
Co-authored-by: Erik Everson <eteverson@gmail.com>
There was already a point that said to provide context, so this
one was not really needed (and a bit confusing).
@namurphy
namurphy requested a review from rocco8773 August 11, 2022 16:24
@namurphy
namurphy merged commit f652d8f into PlasmaPy:main Aug 11, 2022
@namurphy
namurphy deleted the coding-guide-comments-errmsgs branch August 11, 2022 19:58
@namurphy namurphy removed the status: ready for review PRs that are ready for code review label Aug 15, 2022
@namurphy namurphy mentioned this pull request Aug 18, 2022
4 of 8 tasks
namurphy added a commit to namurphy/PlasmaPy that referenced this pull request Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor guide docs PlasmaPy Docs at http://docs.plasmapy.org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants