Best Practices & Code Quality
For development process, please provide the best practices which you are currently following w.r.t below area, and how you have implemented these in automated fashion
Coding best practices
Flutter
- Packages, Libraries, source files should be in snake_case.
- import prefixes using lowercase_with_underscores.
- Use ??and ?. operators
- Use Cascades Operator
- Use debugPrint() for logging in to the console.
- Use const in widgets
- Reusability of code
- Bulk declaration
- Split widgets into sub Widgets.
- Use ListView.builder for a long list
- Use Const in Widgets
- Use async/await overusing futures callback
- Use interpolation to compose strings
GraphQL
- Use Consistent Naming in Your Schema
- Stick to Paginate Lists
- Rely on Unions and Interfaces
- Query only the data you need, where you need it
- Use fragments to encapsulate related sets of fields•Avoid excessive or illogical fragments
- Have a Plan for Error Handling
- Nested Object Queries
- Use Consistent Naming in Your Schema
- Stick to Paginate Lists
- Rely on Unions and Interfaces
- Query only the data you need, where you need it
- Use fragments to encapsulate related sets of fields
- Avoid excessive or illogical fragments
- Have a Plan for Error Handling
- Nested Object Queries
React
- example
PR Best practices
- Authors should provide the details view of code change in comments section before the review
- What has changed
- Why was the change necessary, possibly referencing a formal requirement
- What are direct and indirect consequences of the change
- Logical commits. Each commit should be a single, coherent change.
- All commit messages are descriptive
- The list of commits are related and implement a complete story
- The work in the PR adds quantifiable value.
- Code complies with the defined standards
- The pull request is as small as practically possible
- Do not review for more than 60 minutes at a time
- Reviewers should provide the comment with hint of solution
- Branch should be always rebased with master
- Resolve any conflict before giving for review
Code Quality
SonarCloud
Unit testing & Coverage
React testing Lib, Husky hooks, SonarCloud
Branching and merging strategy
- The code on each branch will need to be fully tested and confidence guaranteed before it is merged to master. The automated tests must be comprehensive.
- Branches must be short lived. The core principle of Continuous Integration and Deployment is that of integrating code frequently. So, if you are doing development on long-lived feature branches then you are no longer integrating code with everybody else frequently enough. This means delayed feedback, big bang merges that can be risky and time consuming to resolve, reduced visibility and reduced confidence.
- Every PR will need to be up to date with the latest version of the master branch.
- Small, incremental changes should be implemented over big bang changes. Frequent small changes are less risky, easier to integrate with and easier to rollback.
Option List :
# | Option Title | Description | Pros & Cons |
---|---|---|---|
1 | GitFlow | GitFlowuses two branches to record the history of the project. The master branch stores the official release history, and the develop branch serves as an integration branch for features. reference: Gitflow Workflow | Atlassian Git Tutorial | Pros:
|
2 | Trunk-Based | In the trunk-based development model, there is a single branch with open access to it, i.e. themasterbranch. Trunk-based development is centred around the concept thatteams should remain in-sync with one another and the application should remain in a state that’s always ready for release with the latest features in place. reference:Trunk-based Development | Atlassian DevOps tech: Trunk-based development | Google Cloud | Pros:
|
Recommendation:
- Trunk-based development strategy to be used
- Automated testing on pull requests will ensure code quality and confidence
- Code linting for maintaining code quality, preventing bugs early enough during commit and adhering to developmental best practices before a pull request is made.
- Naming conventions, pull requests and merging strategies as detailed below
Justification:
Trunk-based development ensures that teams can work quickly and produce high quality, comprehensively tested code. It ensures that branches are simple and the repository is kept clean and tidy.
Naming conventions will follow a set strategy, as detailed below. Having clear guidelines ensures that developers understand the meaning of branch names and commit messages, the repositories can be kept organised, and that the Systems teams can work quickly and easily to build CI/CD pipelines.