What’s a best coding practice, and when to create it?
Tags: programming, productivity, architecture, webdev
Published: 2023-02-01 08:36:47

A best coding practice is a specific action in a particular context, it’s a way of doing things to achieve a specific result. These practices differ between companies and sometimes even between teams within the same company.

Unfortunately, it’s rare that [static analysis tools](https://www.packmind.com/open-source-linters-2021/) (linters) can automatically identify all these coding practices, which go beyond the syntax of the code. That's why it's crucial the whole team is aligned with them.

With this in mind, we created [Packmind](https://packmind.com/), a solution that centralizes your team’s best coding practices.

A coding practice in Packmind is made of:

- a name
- a description
- categories
- code examples (positive, negative, and refactoring)

![An example of best practice](https://miro.medium.com/max/720/0*wMLk8KG17S1BAlKO.webp)

## Why define and share best coding practices?

As companies aim to deliver value as quickly as possible and avoid bugs that are harmful to their business, they must capitalize on the collective intelligence of all their teams.

[Accelerate](https://cloud.google.com/blog/products/devops-sre/dora-2022-accelerate-state-of-devops-report-now-out?hl=en) has highlighted in its study that the most successful companies from an IT point of view have implemented a "[Learning Culture](https://www.packmind.com/learning-culture-software-developers/)," which promotes continuous learning and knowledge sharing. This helps to cope mainly with:

- **Heterogeneity of skills in teams** — everyone can learn from the skills of their colleagues and thus strengthen the team's skills as a whole.
- **Turnover** — newcomers can quickly become familiar with the company's practices, which reduces adaptation time and the risk of losing skills when they leave.
- **Rapidly evolving technologies** — best practices are constantly being renewed, new languages and frameworks appear regularly, so it is important to stay up to date with this. Moreover, on a personal level, this allows developers to remain competitive in a constantly evolving market.

## When to create a best coding practice?

For the whole team to contribute to this knowledge sharing, everyone must have in mind "when" he can create a practice.

In order not to leave the working environment, it must happen when you’re writing code (from your IDE) or when you’re reviewing code (on a [merge request in GitLab](https://docs.gitlab.com/ee/user/project/merge_requests/), for example).

Packmind plugins make this creation easier by allowing the team to [create these practices](https://www.packmind.com/create-best-coding-practices/) in seconds.

2 main scenarios should lead to best practice creation:

- A bug has been identified that stems from a poor design or code error;
- An improvement has been made to the source code

### A bug has been identified that stems from a poor design or code error;

> “One should always learn from your mistakes.”

Strongly linked to the "[Dantotsu](https://www.packmind.com/dantotsu-best-practices/)" approach, the idea is to use each bug as a learning source. Each problem is then presented to the team, and one or several practices can emerge from these discussions.

This is obviously also true for potential bugs that could be avoided, for example, if they’re identified during a code review; in this case, the Packmind plugins allow you to create this practice directly when you add a comment during the code review.

*For example: A bug is identified in an AngularJS component, a disconnection should have occurred when the component is destroyed.*

![Bug in AngularJS](https://miro.medium.com/max/720/0*gdZZo6GTbj_8ztRT)

*And here is the associated fix to follow the best practice.*

![Fixed Bug in AngularJS](https://miro.medium.com/max/720/0*O-tQ_fFwCRVMn3p_)

### An improvement has been made to the source code

Because the source code is constantly evolving, our practices are constantly being challenged. When a practice evolves, it’s rare to modify the entire source code of the product to follow it. It’s, therefore, common to find many different ways of doing things in the same source code.

When a practice evolves, it must be presented to the whole team, and this change must be recorded somewhere. Otherwise, it’s only local and doesn’t last over time.

These practice changes can be of multiple natures, for example:

- A new concept is introduced in the codebase

Adding a new system in the app, to call when adding a new object.

![Trigger event](https://miro.medium.com/max/720/0*leSqH_OTtwdympfF)

- Improvements in the code architecture

Setting up a new pattern to highlight the *infrastructure layer* level.

![Infra layer](https://miro.medium.com/max/720/0*XUKvPEC7h5jNGvj0)

An example that features the outdated convention.

![Infra correction](https://miro.medium.com/max/720/0*CGPmhW_8htJHKSXx)

- Performance, security, and accessibility improvements
- Maintainability improvements (such as better readability of the source code).

Sure, we could list a few more, but these four examples are the main ones that would make your team want to start sharing best coding practices.

## Wrapping up

In conclusion, it’s key to share practices within the team to [improve the ***lead time*** and reduce the ***change failure rate***](https://www.packmind.com/set-learning-culture/). Tech leads must be the drivers and ambassadors of this approach to boost the involvement of the rest of the team.

It’s important not to overestimate the knowledge of other team members. Known as the *Curse of knowledge*, this phenomenon translates into the tendency to think that other people know the same things as we do, so we limit the practices to be presented, even though some of them are probably unknown to our colleagues.

These practices should be shared with all the teams in the company and not only with your team. They’re also valuable for the next team members, so we must think beyond our team when we identify a coding practice.

**Want to discover a new way to share your best coding practices as a team? Start now for free with [Packmind](https://packmind.com/).**