Open thibaultserti opened 3 years ago
Thank you so much for these directions ! In fact, it is quite difficult to have some quality codes when beginning, there are a lot of things to know in order to make a script simple and clear, for both the user and the developer... So I'll try to follow your advices as much as I can for my future projects, and of course starting by improving this program. š
Moreover, I'll leave this issue as opened if you or someone else has other tip to share š
I saw that you are new to coding, so welcome to GitHub !
I listed a few things that you could easily change to improve the quality of your code:
Use f-string instead of ugly concatenation like
print("[INFO] End of OCR, found "+str(NbError)+" errors out of "+str(len(ROI))+" regions...")
print(f"[INFO] End of OCR, found {str(NbError)} errors out of {str(len(ROI))} regions...")
Use logging module instead of
print("[INFO"] ...)
logging.info()
to print a message with the info levelUse a standard docstring notation like the one of google or the one of numpy:
Python Docstring Generator
can generate the docstring based of the prototype function. You can specify if you want the numpy or the google style in the extension configuration.DO NOT write the
.gitignore
yourselfIn the
requirements.txt
, always precise the package version you're usingopencv-python==4.5.1.48
pip3 install virtualenv
python3 -m venv .venv
venv\Scripts\activate
(on Windows)pip install -r requirements.txt
pip freeze
and put this in yourrequirements.txt
insteadYou should use a linter to keep the way you're coding consistent.
black
linter which can be installed bypip install black
format document
, Vscode will propose you the install of black. After that you can format the document by pressing the keyboard shortcut Shift+Ctrl+IIn Vscode, use the Python extension but also the
Visual Studio IntelliCode
andPylance
Small thing, but put a LICENSE to your project (if you want it to be free, MIT License is a good choice)
If you want to go further in devellopping pattern, you can write test for your code.
pytest
frameworkBe sure that it's all about the form and not about the content. The goal of this remarks is simply to make you aware of the existence of such things (ignored by far too many programmers and teachers) and to step up your code quality :smile: