-
Notifications
You must be signed in to change notification settings - Fork 3
Code style guide
This page explains the project's code quality expectations in beginner-friendly language.
The goal is not perfect code. The goal is readable, maintainable code that other contributors can understand and review.
Small changes are easier to review and easier to fix. A good pull request should usually do one thing:
- fix one bug
- add one feature
- improve one part of the documentation
- clean up one focused area
Avoid mixing unrelated changes in the same pull request.
Choose names that explain what something is or does.
Good names:
product_namesell_pricebuy_priceproduct_id
Avoid names that are too short or unclear, unless the meaning is obvious.
- Functions:
snake_case - Classes:
PascalCase - Indentation: 4 spaces
Match what is already in the project.
Do not rewrite or reorganize code unless it is part of the issue you are solving. Unrelated refactoring makes pull requests harder to review.
If you notice cleanup that should be done later, open a separate issue.
We use Ruff for formatting and linting.
Install Ruff:
pip install -r requirements.txtOr directly:
pip install ruffFormat your code:
ruff format .Check for issues:
ruff check .Fix issues automatically:
ruff check --fix .Only format files that are part of your change.
VS Code - Install the Ruff extension and add this to your settings:
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
}
}Zed - Ruff is the default formatter for Python. No setup needed.
PyCharm - Install the Ruff plugin:
- Go to Settings -> Plugins and search for "Ruff".
- Install and restart PyCharm.
- Go to Settings -> Tools -> Ruff.
- Check Enabled and set Run on save to
true. - PyCharm will auto-detect the project's
ruff.toml.
The project's ruff.toml file keeps formatting the same across all editors.
Temporary print statements are useful while developing, but remove them before opening a pull request. Do not leave debug output unless it is part of the intended user experience.
Comments should explain why something is done, not repeat what the code already says.
Helpful comment:
# Keep this check before saving so invalid products never reach the database.Less useful comment:
# Set name to product_name.Avoid leaving commented-out code. If it is not used, delete it.
A function should usually have one clear purpose. If a function becomes long or hard to understand, consider whether part of it should move into a helper function.
Do not split code just to split it. Split code when it becomes easier to read or test.
The app runs in the terminal, so users may type unexpected things. Think about:
- empty input
- wrong type of input
- negative numbers
- unknown commands
- IDs that do not exist
The app should give a useful message and keep running when possible.
Before opening a pull request, check:
- the change solves the linked issue
- the pull request is focused
- the app still starts
- the changed behavior was tested manually
- Ruff has been run
- debug prints are removed
-
data/products.dbis not included - the pull request description explains what changed
Good code is not just code that works. It is code the team can understand, review, and safely build on.