Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Adds a guide to writing code #751

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

a-ovchinnikov
Copy link
Collaborator

This commit adds a reference document with some
best practices to help resolve disputes when
writing code.

Related to: #737

Maintainers will complete the following section

  • Commit messages are descriptive enough
  • Code coverage from testing does not decrease and new code is covered
  • Docs updated (if applicable)
  • Docs links in the code are still valid (if docs were updated)

Note: if the contribution is external (not from an organization member), the CI
pipeline will not run automatically. After verifying that the CI is safe to run:

@slimreaper35
Copy link
Member

Shouldn't be this part of CONTRIBUTING.md ?

@MartinBasti
Copy link
Contributor

Shouldn't be this part of CONTRIBUTING.md ?

Should be linked there at least

@slimreaper35
Copy link
Member

I would not mix docs for package managers and coding best practices 🤷

@eskultety
Copy link
Member

Shouldn't be this part of CONTRIBUTING.md ?

Ideally not. Contributing guidelines are already quite bloated in content, so stylistic things should go to something like "HACKING.md"

Shouldn't be this part of CONTRIBUTING.md ?

Should be linked there at least

Yes, agreed.


## FAQ

Q. Is this guide exhaustive?
Copy link
Contributor

Choose a reason for hiding this comment

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

image
This doesn't render well

@a-ovchinnikov a-ovchinnikov force-pushed the python_coding_guide branch 3 times, most recently from 37e2b22 to 7a4e3be Compare November 29, 2024 16:42
@a-ovchinnikov a-ovchinnikov marked this pull request as ready for review December 3, 2024 14:50

### Write easy to follow code

- Try avoiding extremely long lines in any direction. Horizontal lines longer
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a linter rule that covers this. Is it necessary to add this point here as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Horizontal -- yes, vertical -- not really. I'd have kept it for completeness.

- Consider variable names which reflect intended use and potentially types of
objects they will be bound with.

- While doing the above remember, that vowel shortage is over, so in most
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I completely get what you mean here. Can you add a quick example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lst_pckgs and other overly compacted names. This is not a problem in the codebase yet and arguably I am the one most prone to using them (only in very narrow scopes, but nevertheless).

* [Write clear tests which actually test functionality](#write-clear-tests-which-actually-test-functionality)
* [FAQ](#faq)

## Background
Copy link
Contributor

Choose a reason for hiding this comment

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

Altough I think this section is very well written and is pertinent, I'm afraid that the large text might scare off some people from reading. I feel like the two first paragraphs have the most important messages (we enforce good standards for maintainability, and reviews are done in good faith).

In any case, I'm not strongly against keeping this section as is, so please do so if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was taking a wider look at both CONTRIBUTING.md and coding_best_practices.md, and they might be a little too much information for a newcomer. Maybe we can add some quick reference summaries later on, so one can get up to speed quickly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is intended to be more of a supplementary text and not a must-read. All I do here is reiterate basics. I'll reword the referring sentence in CONTRIBUTING.md to highlight this.

and [PEP20](https://peps.python.org/pep-0020);


### Write clear tests which actually test functionality
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we drop the test guidelines from CONTRIBUTING.md?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. That guide is the main one, this is supplementary.


## Best practices

### Document your decisions
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we drop the comment guidelines from CONTRIBUTING.md?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think no. The idea is that CONTRIBUTING.md is enough for most if not all contributors, and this is a fall-back for cases when we need to explain why certain piece of code does not pass a code review.

@a-ovchinnikov a-ovchinnikov force-pushed the python_coding_guide branch 2 times, most recently from e8c0973 to a82a3e6 Compare December 12, 2024 20:06
This commit adds a reference document with some
best practices to help resolve disputes when
writing code.

Related to: containerbuildsystem#737

Signed-off-by: Alexey Ovchinnikov <[email protected]>
@ben-alkov
Copy link
Member

I really like what's here so far (not least because I strongly agree with all of it 🤣).

Have you considered adding a link to The Zen of Python? I don't know how well-known it is these days, but IMO it's an invaluable resource (outside of Python, even).

@a-ovchinnikov
Copy link
Collaborator Author

a-ovchinnikov commented Dec 17, 2024

Have you considered adding a link to The Zen of Python?

Yes, I have provided a link to 19 of the 20 postulates. Edit: L201, GH keeps rendering the page with the highlight just off screen.

@ben-alkov
Copy link
Member

Have you considered adding a link to The Zen of Python?

Yes, I have provided a link

LOL, I had forgotten that it started life as a PEP 😆

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.

6 participants