Python

Revision | Date | Description |
|---|---|---|
| 24.07.2024 | Init Changelog |
Standards of writing code

To keep quality of writing Python code high there are some basic rules to keep in mind. These rules are intended to:
create code readable for everyone who knows Python;
documenting code in simple way;
track changes;
keep created code secure;
Python is such a simple language that achieving these goals is not particularly complicated.
To achieve them, simply follow the rules below:
Use a active version of Python - based on official site.
Using a currently supported version of the environment partially ensures the security of the code produced (the rest is taken care of by importing the appropriate libraries). All possible vulnerabilities are patched on an ongoing basis by the language creators. Additionally, using the latest version allows you to implement new, interesting functionalities.
Use ready-made libraries if they meet the assumptions!
The Python community is huge. And he is doing a lot of good work in developing this language. If there is no ready-made library, one will probably be created soon. What does this mean for us? Let us use the benefits of the PyPi repository! Instead of calling the curl command in the system shell using Python, stop being stupid and use the ready-made requests library! Why? Because it does exactly the same thing, with the difference that it is more readable, supports Python data types and is much simpler! The same applies to other libraries. What if there is no library that meets our requirements? If you see the point - create one or find a way to write your code in Python style!
Use a version control system (GIT).
This point probably doesn't need to be presented... Why do we upload code to GitLab? Because the code we create belongs to the organization. Bad reason? It's different - because we work as a team. And working as a team means that everyone can contribute something to the code we create - a new functionality, a fix, etc. Git definitely makes working on programming projects easier - even if we work on it alone.
Use branches:
main,develop,working branches!The rules are simple... The branch
mainis used to store the current (production) code. Branchdevelopis used to store code in the development version, not released in production. However,working branchesare used to implement specific functionalities and should start their existence from thedevelopbranch and end their existence after achieving the purpose for which they were created.What has changed in the code recently?
Let's assume that you have created a script that automates some task. You go on vacation, you have fun. Your script is being used passionately by your colleagues, but they needed to add some features to it. You come back from vacation and see that there have been some changes to your code. You want to know what's in it because you don't think it's possible that it's missing something! So... you review the entire code, verify the commits, spend half a day understanding what actually changed! All you had to do was implement a changelog in the repository and maintain it! And that's why we create and maintain it! You can read more about how to keep a changelog, what it is for and who needs it on the Keep a Changelog website.
Read me! That is: what or who am I?
Someone on your team just sent word that they have created a great script that will make your everyday work much easier. You happily open the repository link sent in the message and… Nothing. You see the code files and that's it. You don't know what the script does, you don't know how to use it, what you need for it to work properly. So remember! Create a
README.mdfile in the repository and describe your code in it. Let the people who are going to use it know what it is for! Let them know how to use it! Let them know how to modify it!Automation!