-
Notifications
You must be signed in to change notification settings - Fork 14
Guidelines for contribution
momysnow edited this page Feb 20, 2024
·
2 revisions
In the process of developing code, it is essential to follow best practices aimed at improving the readability, maintainability, and performance of the software. Here are some helpful guidelines:
- Word Separation: Use underscores "_" to separate words in variable names, class names, function names, and other code elements.
- Clear and Consistent Naming: Assign unique, self-explanatory, and consistent names to variables, classes, functions, and other code elements to facilitate understanding and maintenance.
-
Naming Conventions:
- Functions should have lowercase names.
- Libraries should start with an uppercase letter.
- Classes should start with an uppercase letter.
- Avoid Global Variables: Minimize the use of global variables, preferring to declare variables locally to limit side effects and promote encapsulation.
- Encapsulate in Classes: Whenever possible, organize library functions within classes to improve code modularity, reusability, and readability.
- Validate Input Data: Verify and carefully validate input data to prevent errors, vulnerabilities, and unwanted program behaviors.
- Format Input Data: Ensure that input data, including that from APIs or other external sources, is correctly formatted to ensure consistency and compatibility with the rest of the system.
- Avoid Looping: Try to avoid loops whenever possible to improve code efficiency and readability.
- Limit the Use of Pauses: Avoid using pauses in the code unless necessary for specific operations.
- Avoid Recursive Functions: Limit the use of recursive functions to avoid stack overflow and improve performance.
- Code Responsiveness: Strive to make the code as responsive as possible, avoiding rigid solutions and long-blocking operations.
- Code Testing: Practice comprehensive and systematic code testing to identify and correct errors, bugs, and vulnerabilities before they reach the production environment.
- Changes Impacting Code: Ensure that changes made to the code do not affect other parts of the system, and if necessary, update the related code.
- Document the Code: Thoroughly document the code, including exhaustive comments and inline documentation, to facilitate understanding and future maintenance.
- Separate Tasks into Distinct Functions: Organize the code by dividing tasks into distinct functions to improve modularity and readability.
- Create Reusable Functions: Develop functions that can be reused in different parts of the code to reduce duplication and improve maintainability.
- Shorten Functions as Much as Possible: Break long functions into smaller, atomic functions to improve readability and maintainability.
- Library Independence: Ensure that libraries are independent and can function autonomously without external dependencies.
These guidelines will help develop high-quality, robust, and efficient code, enhancing productivity and the quality of the developed software.