|
1 | | -# code-style-guidelines |
| 1 | +# UnifiedBits Code Style Guidelines |
| 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. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 🌍 General Principles |
| 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. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 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. |
| 27 | + |
| 28 | +--- |
| 29 | + |
| 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. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 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. |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 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. |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 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. |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 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. |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 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). |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 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)`. |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 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. |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 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. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## ✅ CI/CD Style Enforcement |
| 136 | + |
| 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. |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +> "Code is read more often than it is written. Let's make it beautiful and consistent." – UnifiedBits |
| 144 | +
|
| 145 | +By following these code style practices, UnifiedBits ensures code quality and a smooth collaborative experience across diverse tech stacks. |
0 commit comments