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

Add a paragraph on bad file names to the style guide #1439

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

vshampor
Copy link
Contributor

No description provided.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Dec 19, 2022
@@ -965,6 +965,11 @@ Always use a `.py` filename extension. Never use dashes.
Python filenames must have a `.py` extension and must not contain dashes (`-`).
This allows them to be imported and unit tested.

Avoid file and module names of `utils`, `helpers` etc. and do not extend existing files and packages with these names.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In all of these examples the utils part can either be removed without loss of semantic meaning, or replaced to a more fitting name (e.g. the transformers example seems to contain mostly test and CI scripts and checkers - there are your two-three names (tests, ci_checks, checks) that could be used instead of utils.

Copy link
Contributor

Choose a reason for hiding this comment

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

PyTorch contains quite a lot of stuff in utils moving to torch namespace will make it messy. The content of Keras also disapproves of your statement.
How does logging fit the common namespace in your case? The name common should also fall into the rule you proposed in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, not really messier than it already is. I don't see how torch.utils.jit.log_extract from their code is better kept in torch.utils.jit rather than in the already existing torch.jit, and why torch.jit._decomposition_utils is not torch.utils.jit._decomposition. As for Keras - I'm sure that bad decisions can be found in any code base, Google's is no exception.

As mentioned, common is a descriptive name in a sense that it separates the backend-agnostic code and definitions from the backend-specific code. I can add a README.md file to that module like I did in tests/common and tests/shared to give a more documental definition for this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Some point from https://maestros.io/whats-in-a-utils-file

I came across to a utils.js -or something like that- it was a real headache. I had to guess what's in there.

I agree that avoid utils and helpers names is good practices. Put code to utils it's the easiest way, better find correct names that will display the functionality. But don't need to strictly follow this, otherwise there will be many small files.

Copy link
Collaborator

@AlexanderDokuchaev AlexanderDokuchaev Dec 19, 2022

Choose a reason for hiding this comment

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

For example my PR https://github.com/openvinotoolkit/nncf/pull/1404/files, for me several function can be added to utils.py. But it's can be already discussed.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, not really messier than it already is. I don't see how torch.utils.jit.log_extract from their code is better kept in torch.utils.jit rather than in the already existing torch.jit, and why torch.jit._decomposition_utils is not torch.utils.jit._decomposition. As for Keras - I'm sure that bad decisions can be found in any code base, Google's is no exception.

As mentioned, common is a descriptive name in a sense that it separates the backend-agnostic code and definitions from the backend-specific code. I can add a README.md file to that module like I did in tests/common and tests/shared to give a more documental definition for this.

Common can be descriptive for backend-agnostic code but logging is not related to backends at all. I recommend not mixing the repository folder layout and import layout because these are two different things. The former is our internal reasonable preferences while the latter is what and how we expose this to the user.
The initially proposed guidance does not make sense to me. @alexsu52, proposed a different rule of thumb in the style guide, and I support it.

Copy link
Contributor Author

@vshampor vshampor Dec 20, 2022

Choose a reason for hiding this comment

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

backend-agnostic code but logging is not related to backends at all

Is backend-agnostic code related to backends, and if so, how is this different from how logging is related to backends?

I recommend not mixing the repository folder layout and import layout because these are two different things.

Good luck doing this in Python without code-generation and importlib magic.

The initially proposed guidance does not make sense to me. @alexsu52, proposed a different rule of thumb in the style guide, and I support it.

@alexsu52's wording is a subset of mine. Mine is stronger and also gives a description of consequences and of what to do instead of the wrong behaviour. I stand by my wording.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have update the paragraph to integrate @alexsu52's wording, shortened it somewhat and added examples of good and bad layouts. I also kept a short sentence on what to do instead, so that the recommendation is not just a plain prohibition but also describes a course of action.

Comment on lines 968 to 971
Avoid file and module names of `utils`, `helpers` etc. and do not extend existing files and packages with these names.
Otherwise there is always a temptation to add an additional piece of code to this file/module, which ends up in having large files with unrelated functions and classes.
Instead group your new code in dedicated files/modules that are named explicitly according to the purpose of code - either create new files/modules for this or extend the already existing, properly named ones.
If you see an opportunity to break down a `utils.py` or `helpers.py` file into a better named and grouped set of files - take it.
Copy link
Contributor

@alexsu52 alexsu52 Dec 20, 2022

Choose a reason for hiding this comment

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

Suggested change
Avoid file and module names of `utils`, `helpers` etc. and do not extend existing files and packages with these names.
Otherwise there is always a temptation to add an additional piece of code to this file/module, which ends up in having large files with unrelated functions and classes.
Instead group your new code in dedicated files/modules that are named explicitly according to the purpose of code - either create new files/modules for this or extend the already existing, properly named ones.
If you see an opportunity to break down a `utils.py` or `helpers.py` file into a better named and grouped set of files - take it.
Avoid creating Python files like a "swiss knife" by naming them with common names such as `utils.py`, `helpers.py`, `common.py` and etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrote the paragraph, please re-review.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's handle *.py at the first.

@vshampor vshampor requested a review from a team as a code owner November 17, 2023 13:54
@vshampor vshampor requested a review from alexsu52 November 17, 2023 13:55
Copy link

codecov bot commented Nov 17, 2023

Codecov Report

Merging #1439 (2b6cc07) into develop (b6910ea) will decrease coverage by 3.92%.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1439      +/-   ##
===========================================
- Coverage    89.86%   85.94%   -3.92%     
===========================================
  Files          485      485              
  Lines        44491    43744     -747     
===========================================
- Hits         39981    37596    -2385     
- Misses        4510     6148    +1638     
Flag Coverage Δ
COMMON 15.82% <ø> (+0.07%) ⬆️
ONNX ?
OPENVINO 38.65% <ø> (+0.02%) ⬆️
TENSORFLOW 30.03% <ø> (-0.02%) ⬇️
TORCH 62.71% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 55 files with indirect coverage changes

Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

LGTM

@vshampor vshampor merged commit 2e48ffb into openvinotoolkit:develop Nov 20, 2023
6 checks passed
@vshampor vshampor deleted the style_adjustments branch January 9, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants