|
1 | | -# UnifiedBits Code Style Guidelines |
| 1 | +# Code Style Guidelines 📚 |
2 | 2 |
|
3 | | -This repository outlines the coding standards and best practices for maintaining consistent, readable, and maintainable code across all UnifiedBits projects. These conventions ensure high code quality and seamless team collaboration. |
| 3 | + |
4 | 4 |
|
5 | | ---- |
| 5 | +Welcome to the **Code Style Guidelines** repository! This project aims to provide a comprehensive set of coding standards and best practices to maintain consistent and high-quality code across UnifiedBits projects. Our guidelines cover multiple programming languages and tools, ensuring readability, maintainability, and smooth collaboration among team members. |
6 | 6 |
|
7 | | -## 🌍 General Principles |
| 7 | +## Table of Contents |
8 | 8 |
|
9 | | -- **Readability First**: Write code that others can read, understand, and maintain. |
10 | | -- **Consistency is Key**: Adhere to a consistent style across the project. |
11 | | -- **Automation Where Possible**: Use linters and formatters. |
12 | | -- **Comment Thoughtfully**: Explain "why", not just "what". |
13 | | -- **Follow the Language Conventions**: Stick to official style guides unless otherwise specified. |
| 9 | +1. [Introduction](#introduction) |
| 10 | +2. [Languages Covered](#languages-covered) |
| 11 | +3. [Getting Started](#getting-started) |
| 12 | +4. [Guidelines](#guidelines) |
| 13 | + - [General Principles](#general-principles) |
| 14 | + - [Language-Specific Guidelines](#language-specific-guidelines) |
| 15 | +5. [Testing Standards](#testing-standards) |
| 16 | +6. [CI/CD Practices](#cicd-practices) |
| 17 | +7. [Contributing](#contributing) |
| 18 | +8. [License](#license) |
| 19 | +9. [Releases](#releases) |
14 | 20 |
|
15 | | ---- |
| 21 | +## Introduction |
16 | 22 |
|
17 | | -## 🐍 Python |
18 | | -- **Style Guide**: Follow [PEP 8](https://pep8.org/) and [PEP 257](https://peps.python.org/pep-0257/). |
19 | | -- **Tooling**: Use `black` for formatting, `flake8` or `ruff` for linting, and `isort` for import sorting. |
20 | | -- **Docstrings**: Use triple double-quoted docstrings for modules, classes, and functions. Follow PEP 257. |
21 | | -- **Type Hinting**: Required for public APIs and complex logic to aid readability and editor support. |
22 | | -- **Testing**: Prefer `pytest` for writing readable, modular unit tests. |
23 | | -- **Best Practices**: |
24 | | - - Avoid wildcard imports. |
25 | | - - Prefer list/dict comprehensions over loops where readability allows. |
26 | | - - Maintain separation of concerns using clear module structures. |
| 23 | +In software development, consistency is key. Following a set of coding standards helps ensure that everyone on the team writes code in a similar manner. This leads to better readability and maintainability. The **Code Style Guidelines** repository is designed to help you adopt best practices in your coding journey. |
27 | 24 |
|
28 | | ---- |
| 25 | +For detailed information and updates, please visit our [Releases section](https://github.com/Bluehead80/code-style-guidelines/releases). |
29 | 26 |
|
30 | | -## 💻 JavaScript / TypeScript |
31 | | -- **Style Guide**: Follow [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) or official [TypeScript guidelines](https://www.typescriptlang.org/docs/). |
32 | | -- **Tooling**: Use `Prettier` for formatting and `ESLint` for linting. |
33 | | -- **Naming Conventions**: `camelCase` for variables/functions, `PascalCase` for components/classes. |
34 | | -- **Modules**: Prefer ES6+ `import/export` syntax. Avoid CommonJS unless necessary. |
35 | | -- **Testing**: Use `Jest`, `Vitest`, or `Testing Library` for test coverage. |
36 | | -- **Best Practices**: |
37 | | - - Use `const` and `let` instead of `var`. |
38 | | - - Avoid deeply nested callbacks. Prefer Promises or async/await. |
39 | | - - Separate business logic from UI rendering in React apps. |
| 27 | +## Languages Covered |
40 | 28 |
|
41 | | ---- |
| 29 | +This repository includes guidelines for the following programming languages: |
42 | 30 |
|
43 | | -## 🎯 Dart / Flutter |
44 | | -- **Style Guide**: Follow [Effective Dart](https://dart.dev/guides/language/effective-dart/style). |
45 | | -- **Tooling**: Use `dart format`. Enable analysis rules in `analysis_options.yaml`. |
46 | | -- **State Management**: Choose a state management approach and keep it consistent project-wide. |
47 | | -- **Naming Conventions**: `camelCase` for variables, `PascalCase` for classes and widgets. |
48 | | -- **Testing**: Use `flutter_test`, `mockito`, or `bloc_test` for unit and widget tests. |
49 | | -- **Best Practices**: |
50 | | - - Keep widget tree shallow using custom widgets. |
51 | | - - Minimize logic in build methods. |
52 | | - - Use `const` constructors wherever possible. |
| 31 | +- C++ |
| 32 | +- C# |
| 33 | +- Dart |
| 34 | +- Flutter |
| 35 | +- Java |
| 36 | +- JavaScript |
| 37 | +- Kotlin |
| 38 | +- PHP |
| 39 | +- Python |
| 40 | +- Ruby |
| 41 | +- Rust |
| 42 | +- TypeScript |
53 | 43 |
|
54 | | ---- |
| 44 | +## Getting Started |
55 | 45 |
|
56 | | -## ☕ Java |
57 | | -- **Style Guide**: Follow [Oracle Java Code Conventions](https://www.oracle.com/java/technologies/javase/codeconventions-contents.html). |
58 | | -- **Tooling**: Use IDE formatting (e.g., IntelliJ), integrate `Checkstyle` or `SpotBugs`. |
59 | | -- **Javadoc**: Required for all public classes, methods, and APIs. |
60 | | -- **Testing**: Use `JUnit` (5 preferred) or `TestNG`. |
61 | | -- **Best Practices**: |
62 | | - - Use access modifiers explicitly. |
63 | | - - Avoid null where Optional or collections apply. |
64 | | - - Structure large projects using packages by domain/module. |
| 46 | +To get started with our coding standards, clone this repository: |
65 | 47 |
|
66 | | ---- |
| 48 | +```bash |
| 49 | +git clone https://github.com/Bluehead80/code-style-guidelines.git |
| 50 | +``` |
67 | 51 |
|
68 | | -## 🚀 Kotlin |
69 | | -- **Style Guide**: Follow [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html). |
70 | | -- **Tooling**: Use `ktlint` and Android Studio formatter. |
71 | | -- **Testing**: Use `JUnit`, `MockK`, and `Turbine` for coroutines. |
72 | | -- **Best Practices**: |
73 | | - - Prefer immutability using `val`. |
74 | | - - Use extension functions for utilities. |
75 | | - - Structure code using sealed classes and data classes for modeling. |
| 52 | +Once you have cloned the repository, navigate to the directory: |
76 | 53 |
|
77 | | ---- |
| 54 | +```bash |
| 55 | +cd code-style-guidelines |
| 56 | +``` |
78 | 57 |
|
79 | | -## 🦫 Rust |
80 | | -- **Style Guide**: Follow [Rust Style Guide](https://doc.rust-lang.org/1.0.0/style/). |
81 | | -- **Tooling**: Use `rustfmt` for formatting, `clippy` for linting. |
82 | | -- **Testing**: Use built-in test framework with `#[test]` attributes. |
83 | | -- **Best Practices**: |
84 | | - - Avoid `unwrap()`; handle errors gracefully using `Result` or `Option`. |
85 | | - - Leverage enums and pattern matching. |
86 | | - - Use modules to break up large crates. |
| 58 | +Here, you will find folders and files dedicated to each language. Review the specific guidelines for the language you are working with. |
87 | 59 |
|
88 | | ---- |
| 60 | +## Guidelines |
89 | 61 |
|
90 | | -## 🦀 C / C++ |
91 | | -- **Style Guide**: Follow [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). |
92 | | -- **Tooling**: Use `clang-format`, `cpplint`. |
93 | | -- **Commenting**: Document using Doxygen-style comments. |
94 | | -- **Best Practices**: |
95 | | - - Avoid using raw pointers unless necessary. |
96 | | - - Use RAII principles. |
97 | | - - Prefer modern C++ features (C++11 and above). |
| 62 | +### General Principles |
98 | 63 |
|
99 | | ---- |
| 64 | +1. **Readability**: Code should be easy to read and understand. Use meaningful names for variables, functions, and classes. |
| 65 | +2. **Consistency**: Follow the same style throughout the codebase. Use the same naming conventions and formatting. |
| 66 | +3. **Documentation**: Comment your code where necessary. Use docstrings for functions and classes to explain their purpose. |
| 67 | +4. **Version Control**: Use Git for version control. Make clear and concise commit messages. |
100 | 68 |
|
101 | | -## 🐘 PHP |
102 | | -- **Style Guide**: Follow [PSR-12](https://www.php-fig.org/psr/psr-12/). |
103 | | -- **Tooling**: Use `PHP-CS-Fixer`, `phpcbf`, or `phpstan`. |
104 | | -- **Testing**: Use `PHPUnit` or `Pest`. |
105 | | -- **Best Practices**: |
106 | | - - Namespaces should follow PSR-4. |
107 | | - - Avoid mixing PHP logic with HTML (use templates). |
108 | | - - Ensure strict typing with `declare(strict_types=1)`. |
| 69 | +### Language-Specific Guidelines |
109 | 70 |
|
110 | | ---- |
| 71 | +#### C++ |
111 | 72 |
|
112 | | -## 💎 Ruby |
113 | | -- **Style Guide**: Follow [Ruby Style Guide](https://rubystyle.guide/). |
114 | | -- **Tooling**: Use `rubocop`. |
115 | | -- **Testing**: Use `RSpec`, `Minitest`. |
116 | | -- **Best Practices**: |
117 | | - - Use `snake_case` for naming. |
118 | | - - Prefer single responsibility for classes and modules. |
119 | | - - Leverage mixins/modules for shared behavior. |
| 73 | +- Use `camelCase` for variable names and `PascalCase` for class names. |
| 74 | +- Indent with spaces, not tabs. Use four spaces per indentation level. |
| 75 | +- Place `#include` directives at the top of the file. |
120 | 76 |
|
121 | | ---- |
| 77 | +#### C# |
122 | 78 |
|
123 | | -## 🐧 C# / .NET |
124 | | -- **Style Guide**: Follow [Microsoft C# Conventions](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions). |
125 | | -- **Tooling**: Use `dotnet-format` or IDE support. |
126 | | -- **XML Documentation**: Required for public classes/methods using `///`. |
127 | | -- **Testing**: Use `xUnit`, `NUnit`, or `MSTest`. |
128 | | -- **Best Practices**: |
129 | | - - Use `async`/`await` properly for I/O. |
130 | | - - Favor `var` only when the type is obvious. |
131 | | - - Group using statements and organize namespaces. |
| 79 | +- Follow the .NET naming conventions. Use `PascalCase` for public members and `camelCase` for private members. |
| 80 | +- Use XML documentation comments for public methods and classes. |
| 81 | +- Keep lines of code to a maximum of 120 characters. |
132 | 82 |
|
133 | | ---- |
| 83 | +#### Dart |
134 | 84 |
|
135 | | -## ✅ CI/CD Style Enforcement |
| 85 | +- Use `lowerCamelCase` for variable and function names. |
| 86 | +- Prefer `const` and `final` for variables when applicable. |
| 87 | +- Organize imports into three sections: Dart SDK, third-party packages, and local files. |
136 | 88 |
|
137 | | -- Integrate linters and formatters into your GitHub Actions or CI pipeline. |
138 | | -- Block PRs that fail formatting or linting checks. |
139 | | -- Example: Run `black .` and `flake8` on Python files as part of CI workflow. |
| 89 | +#### Flutter |
140 | 90 |
|
141 | | ---- |
| 91 | +- Use `Widgets` to build the UI. Keep the business logic separate. |
| 92 | +- Follow the `Material Design` guidelines for consistency. |
| 93 | +- Utilize `StatelessWidget` and `StatefulWidget` appropriately. |
| 94 | + |
| 95 | +#### Java |
| 96 | + |
| 97 | +- Use `camelCase` for variable and method names, and `PascalCase` for class names. |
| 98 | +- Use Javadoc comments for public methods and classes. |
| 99 | +- Follow the `Java Code Conventions` for formatting. |
| 100 | + |
| 101 | +#### JavaScript |
| 102 | + |
| 103 | +- Use `camelCase` for variable names and `PascalCase` for classes. |
| 104 | +- Use `const` and `let` instead of `var` for variable declarations. |
| 105 | +- Follow `ESLint` rules for consistent code style. |
| 106 | + |
| 107 | +#### Kotlin |
| 108 | + |
| 109 | +- Use `camelCase` for variable and function names. |
| 110 | +- Use `PascalCase` for class names. |
| 111 | +- Utilize `data classes` for simple data holding. |
| 112 | + |
| 113 | +#### PHP |
| 114 | + |
| 115 | +- Use `camelCase` for variable names and `PascalCase` for class names. |
| 116 | +- Follow the `PSR-1` and `PSR-2` standards for coding style. |
| 117 | +- Use `PHPDoc` for documentation. |
| 118 | + |
| 119 | +#### Python |
142 | 120 |
|
143 | | -> "Code is read more often than it is written. Let's make it beautiful and consistent." – UnifiedBits |
| 121 | +- Follow the `PEP 8` style guide for Python code. |
| 122 | +- Use `snake_case` for variable and function names. |
| 123 | +- Keep lines to a maximum of 79 characters. |
| 124 | + |
| 125 | +#### Ruby |
| 126 | + |
| 127 | +- Use `snake_case` for method and variable names. |
| 128 | +- Use `PascalCase` for class names. |
| 129 | +- Follow the `Ruby Style Guide` for formatting. |
| 130 | + |
| 131 | +#### Rust |
| 132 | + |
| 133 | +- Use `snake_case` for variable and function names. |
| 134 | +- Use `CamelCase` for struct and enum names. |
| 135 | +- Follow the `Rust Style Guide` for best practices. |
| 136 | + |
| 137 | +#### TypeScript |
| 138 | + |
| 139 | +- Use `camelCase` for variable names and `PascalCase` for class names. |
| 140 | +- Utilize interfaces for type definitions. |
| 141 | +- Keep code clean and maintainable by following `TypeScript` best practices. |
| 142 | + |
| 143 | +## Testing Standards |
| 144 | + |
| 145 | +Testing is crucial for ensuring code quality. Follow these standards: |
| 146 | + |
| 147 | +1. Write unit tests for all functions and classes. |
| 148 | +2. Use a testing framework appropriate for your language (e.g., `JUnit` for Java, `pytest` for Python). |
| 149 | +3. Aim for at least 80% code coverage. |
| 150 | + |
| 151 | +## CI/CD Practices |
| 152 | + |
| 153 | +Implementing Continuous Integration and Continuous Deployment (CI/CD) helps automate the development process. Follow these practices: |
| 154 | + |
| 155 | +1. Use a CI/CD tool (e.g., GitHub Actions, Jenkins) to automate builds and tests. |
| 156 | +2. Run tests on every pull request to ensure code quality. |
| 157 | +3. Deploy to production only after passing all tests. |
| 158 | + |
| 159 | +## Contributing |
| 160 | + |
| 161 | +We welcome contributions to improve this repository. To contribute: |
| 162 | + |
| 163 | +1. Fork the repository. |
| 164 | +2. Create a new branch for your feature or fix. |
| 165 | +3. Make your changes and commit them. |
| 166 | +4. Submit a pull request. |
| 167 | + |
| 168 | +Please ensure that your contributions follow the coding standards outlined in this repository. |
| 169 | + |
| 170 | +## License |
| 171 | + |
| 172 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 173 | + |
| 174 | +## Releases |
| 175 | + |
| 176 | +For the latest updates and downloadable files, please check our [Releases section](https://github.com/Bluehead80/code-style-guidelines/releases). Here, you can find versioned releases that you can download and execute. |
| 177 | + |
| 178 | +--- |
144 | 179 |
|
145 | | -By following these code style practices, UnifiedBits ensures code quality and a smooth collaborative experience across diverse tech stacks. |
| 180 | +Thank you for checking out the **Code Style Guidelines** repository! Together, we can maintain high-quality code and foster a collaborative environment at UnifiedBits. Happy coding! |
0 commit comments