-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
patched.codes[bot]
committed
Oct 9, 2024
1 parent
b3b6f22
commit 0fb6091
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Code Style Guidelines | ||
|
||
## 1. Naming Conventions | ||
- Use descriptive and meaningful names for variables, functions, and classes. | ||
- Follow the language-specific naming conventions (e.g., camelCase for JavaScript, snake_case for Python). | ||
- Prefix private methods and variables with an underscore. | ||
- Use UPPERCASE for constants. | ||
|
||
## 2. Code Structure | ||
- Keep functions and methods small and focused on a single task. | ||
- Limit the number of parameters in functions (aim for 3 or fewer). | ||
- Use appropriate indentation and consistent formatting. | ||
- Group related code together and separate different concerns. | ||
- Avoid deep nesting; extract complex conditions into separate functions. | ||
|
||
## 3. Documentation | ||
- Write clear and concise comments for complex logic or non-obvious code. | ||
- Use docstrings or appropriate documentation formats for functions, classes, and modules. | ||
- Keep comments up-to-date with code changes. | ||
- Include examples in documentation when appropriate. | ||
|
||
## 4. Error Handling | ||
- Use specific exception types and avoid catching generic exceptions. | ||
- Provide informative error messages. | ||
- Log errors with appropriate context for debugging. | ||
- Handle errors at the appropriate level of abstraction. | ||
|
||
## 5. Performance | ||
- Optimize code only when necessary, prioritizing readability and maintainability. | ||
- Use appropriate data structures and algorithms for the task at hand. | ||
- Avoid unnecessary computations or memory allocations. | ||
- Consider caching results of expensive operations when appropriate. | ||
|
||
## 6. Security | ||
- Validate and sanitize all user inputs. | ||
- Use parameterized queries to prevent SQL injection. | ||
- Implement proper authentication and authorization mechanisms. | ||
- Avoid storing sensitive information in plain text; use encryption where necessary. | ||
- Keep dependencies up-to-date and regularly check for known vulnerabilities. | ||
|
||
## 7. Testing | ||
- Write unit tests for all new code and maintain existing tests. | ||
- Aim for high test coverage, especially for critical paths. | ||
- Use meaningful test names that describe the behavior being tested. | ||
- Keep tests independent and avoid dependencies between test cases. | ||
|
||
## 8. Version Control | ||
- Write clear and descriptive commit messages. | ||
- Make small, focused commits that address a single issue or feature. | ||
- Use feature branches for new development and merge regularly with the main branch. | ||
- Perform code reviews before merging changes into the main branch. | ||
|
||
## 9. Code Reusability | ||
- Follow the DRY (Don't Repeat Yourself) principle to avoid code duplication. | ||
- Create reusable components, functions, or modules for common operations. | ||
- Use appropriate design patterns to solve recurring problems. | ||
|
||
## 10. Maintenance | ||
- Regularly refactor code to improve its structure and readability. | ||
- Remove dead code and unused variables. | ||
- Keep the codebase clean by addressing technical debt regularly. | ||
- Document any workarounds or temporary solutions, including the reasons and plans for future improvements. |