Style Guide
This style guide provides best practices, coding conventions, and standards for writing clean, maintainable, and consistent code across our projects. Following these guidelines ensures that our codebase is readable, collaborative, and scalable.
Table of Contents
- General Principles
- Naming Conventions
- Formatting and Indentation
- Comments and Documentation
- Language-Specific Guidelines
- Testing and Code Quality
- Version Control Practices
- Security Best Practices
- Collaboration and Code Reviews
- Linting and Tooling
- Khmer Language & Localization Standards
- References
General Principles
- Write clear and readable code. Prioritize readability over cleverness.
- Follow consistent patterns across the project.
- Keep functions and modules small and focused.
- Use descriptive names for variables, functions, and classes.
- Follow official language and framework best practices whenever possible.
- Handle errors and exceptions gracefully.
- Write self-documenting code wherever possible.
Naming Conventions
- Use camelCase for variables and functions (exceptions: Python uses snake_case).
- Use PascalCase for classes and components.
- Constants should be in UPPER_CASE.
- Prefix private/internal variables with
_where supported. - Be consistent across modules and packages.
- Use meaningful names that describe purpose and usage.
Formatting and Indentation
- Follow language-specific indentation rules (usually 2 or 4 spaces).
- Keep lines under 80–120 characters where possible.
- Use blank lines to separate logical sections.
- Use a consistent brace style (K&R, Allman, or language default).
- Avoid deep nesting; refactor code into smaller functions if necessary.
Comments and Documentation
- Write comments for complex logic, not obvious code.
- Use docstrings or JSDoc-style comments for functions, classes, and modules.
- Keep comments up-to-date with code changes.
- Document public APIs clearly with parameters, return values, and examples.
- Include inline comments sparingly to explain why, not what.
Language-Specific Guidelines
Java
- Follow Google Java Style Guide: https://google.github.io/styleguide/javaguide.html
- Use CamelCase for classes and methods.
- Prefer interfaces for abstraction and avoid deep inheritance chains.
- Avoid magic numbers; use named constants.
- Use try-with-resources for automatic resource management.
JavaScript / TypeScript
- Follow Airbnb JavaScript Style Guide: https://github.com/airbnb/javascript
- Use const/let instead of var.
- Prefer arrow functions for anonymous functions.
- TypeScript: enable strict typing.
- Use template literals for string concatenation.
Python
- Follow PEP 8: https://peps.python.org/pep-0008/
- Use snake_case for variables and functions.
- Use PascalCase for class names.
- Keep functions short and modular.
- Prefer list comprehensions for concise loops.
C#
- Follow Microsoft C# Coding Conventions: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style
- Use PascalCase for types and methods.
- Keep method lengths manageable and follow SOLID principles.
- Document public APIs with XML comments.
Other Languages
- Always refer to the official style guide for the language or framework.
- Maintain consistency within the project even if guidelines vary across languages.
- Examples:
- Go: Effective Go
- Ruby: Ruby Style Guide
Testing and Code Quality
- Write unit tests for all critical functions.
- Use integration and end-to-end tests for complete workflows.
- Follow Test-Driven Development (TDD) or Behavior-Driven Development (BDD) where possible.
- Maintain meaningful test coverage; prioritize quality over quantity.
- Integrate automated testing into CI/CD pipelines when possible.
Version Control Practices
- Commit frequently with descriptive messages.
- Use consistent branch naming conventions:
feature/<feature-name>bugfix/<issue-id>hotfix/<issue-id>
- Rebase before merging if linear history is preferred.
- Use Pull Requests for code review and team collaboration.
Security Best Practices
- Never store secrets, passwords, or API keys in code repositories.
- Validate and sanitize all input to prevent vulnerabilities (e.g., SQL Injection, XSS).
- Follow secure coding guidelines for each language.
- Regularly update dependencies to patch known vulnerabilities.
- Use HTTPS, encryption, and authentication standards consistently.
Collaboration and Code Reviews
- Use Pull Requests to discuss, review, and approve code.
- Provide constructive feedback focused on code quality, readability, and maintainability.
- Review for adherence to style guide, security, and best practices.
- Encourage team knowledge sharing during reviews.
- Document architectural or complex decisions in PR descriptions or design docs.
Linting and Tooling
- Enable linters and formatters to enforce style rules automatically.
- Common tools:
- JavaScript/TypeScript: ESLint + Prettier
- Python: flake8 + black
- Java: Checkstyle
- C#: Roslyn analyzers
- Use pre-commit hooks to ensure code style is checked before commits.
Khmer Language & Localization Standards
- Use UTF-8 encoding exclusively for all source codes, APIs, configuration files, and databases to ensure full Khmer Unicode compatibility.
- Support proper handling of Zero-Width Space (ZWSP / U+200B) since Khmer text does not use spaces between words.
- Ensure front-end systems correctly wrap Khmer text on mobile and web screens without breaking layout or readability.
- Use Unicode-compliant Khmer fonts only.
- For web applications, prioritize Google Fonts such as Battambang, Siemreap, or Kantumruy to ensure consistent rendering across government devices.
- Test rendering across major browsers and devices to validate consonant stacking, diacritic placement, and responsive text wrapping.
References
- Google Java Style Guide
- Airbnb JavaScript Style Guide
- PEP 8 – Python Style Guide
- Microsoft C# Coding Conventions
- Effective Go
- Ruby Style Guide
Note: This Style Guide is a living document. Updates will be made periodically to reflect new best practices, tools, and language features. Always refer to official guides for the most current recommendations.