Skip to content

4. Coding Standards

Formatting Guidelines

Purpose:

  • Consistent code formatting improves readability, maintainability, and collaboration among developers. Establishing formatting guidelines ensures that codebases remain clean, organized, and easy to understand.

Guidelines:

  • Utilize tools like Dartfmt to automatically format code according to predefined standards.
  • Define rules for indentation, line length, spacing, and code alignment to maintain a consistent style across the codebase.
  • Configure editor settings or IDE plugins to enforce formatting rules and automatically format code on save or commit.

Naming Conventions

Purpose:

  • Naming conventions provide a consistent and predictable way to name variables, functions, classes, and other identifiers in the codebase. Clear and descriptive names enhance code readability and comprehension.

Guidelines:

  • Use meaningful and descriptive names that accurately reflect the purpose and functionality of the identifier.
  • Follow established naming conventions for different types of identifiers (e.g., camelCase for variables and functions, PascalCase for classes and enums).
  • Avoid abbreviations, acronyms, or overly cryptic names that may obscure the meaning of identifiers.

Code Organization

Purpose:

  • Organizing code effectively improves maintainability, scalability, and navigation within the codebase. A well-structured codebase follows a logical organization scheme that makes it easy to locate and understand relevant code components.

Guidelines:

  • Group related code files into logical directories or packages based on functionality or domain.
  • Follow the separation of concerns principle to separate different layers of the application (e.g., presentation, business logic, data access).
  • Modularize code into reusable components, modules, or libraries to promote code reuse and minimize duplication.
  • Define clear boundaries between modules and establish communication interfaces to facilitate decoupling and dependency management.

Best Practices

Purpose:

  • Best practices encapsulate proven techniques, patterns, and approaches for writing efficient, maintainable, and scalable Flutter code. Adhering to best practices ensures that codebases maintain high quality, performance, and reliability over time.

Guidelines:

  • Leverage Flutter's built-in widgets and components whenever possible to maintain consistency with the platform and leverage performance optimizations.
  • Follow Flutter's widget composition principles to build complex UIs from simple, composable components.
  • Implement state management patterns (e.g., Provider, Bloc) to manage application state and data flow effectively.
  • Handle errors and exceptions gracefully to provide a robust and resilient user experience.