# Clean Code definition

We define Clean Code as code that has the following attributes: consistency, intentionality, adaptability, and responsibility.

![](https://3272878703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI10pmJWeVVXYITlQJllp%2Fuploads%2Fgit-blob-0e61ea1b649a8f4c8e5bc09da7604737e61a5a17%2Fb7517b3ce586e9cba105b12a5726c14dccf82bda.png?alt=media)

## Consistency <a href="#consistency" id="consistency"></a>

The code is written in a uniform and conventional way. All the code looks similar and follows a regular pattern, even with multiple contributors at different times.

Consistent code is formatted, conventional, and identifiable.

### Formatted <a href="#formatted" id="formatted"></a>

The code presentation is systematic and regular. Non-semantic choices, such as spacing, indentation, and character placement, remain consistent throughout the codebase, maintaining uniformity across files and authors.

### Conventional <a href="#conventional" id="conventional"></a>

The code performs tasks with expected instructions. Faced with equally good options, the code adheres to a single choice across all instances, preferring language conventions. This includes using the appropriate programming interfaces and language features.

### Identifiable <a href="#identifiable" id="identifiable"></a>

The names follow a regular structure based on language conventions. The casing, word separators, suffixes, and prefixes used in the identifiers have purpose, without arbitrary differences.

## Intentionality <a href="#intentionality" id="intentionality"></a>

The code is precise and purposeful. Every instruction makes sense, is adequately formed, and clearly communicates its behavior.

Intentional code is clear, logical, complete, and efficient.

### Clear <a href="#clear" id="clear"></a>

The code is self-explanatory, transparently communicating its functionality. It is written in a straightforward way that minimizes ambiguity, avoiding unnecessary clever or intricate solutions.

### Logical <a href="#logical" id="logical"></a>

The code has well-formed and sound instructions that work together. It is free of explicit errors, contradictions, and commands that could be unpredictable or objectionable.

### Complete <a href="#complete" id="complete"></a>

The code constructs are comprehensive and used adequately and thoroughly. The code is functional and achieves its implied goals. There are no obviously incomplete or lacking solutions.

### Efficient <a href="#efficient" id="efficient"></a>

The code uses resources without needless waste. It prioritizes economical options when available, avoiding unnecessary consumption of memory, processor, disk, or network resources.

## Adaptability <a href="#adaptability" id="adaptability"></a>

The code is structured to be easy to evolve and develop with confidence. It makes extending or repurposing its parts easy and promotes localized changes without undesirable side-effects.

Adaptable code is focused, distinct, modular, and tested.

### Focused <a href="#focused" id="focused"></a>

The code has a single, narrow, and specific scope. Each unit should have only one concise purpose, without an overwhelming accumulation of instructions or excessive amounts of complexity.

### Distinct <a href="#distinct" id="distinct"></a>

The code procedures and data are unique and distinctive, without undue duplication. The codebase has no significant repetition where it could be decomposed into smaller shared segments.

### Modular <a href="#modular" id="modular"></a>

The code has been organized and distributed to emphasize the separation between its parts. The relationships within the code are carefully managed, ensuring they are minimal and clearly defined.

### Tested <a href="#tested" id="tested"></a>

The code has automated checks that provide confidence in the functionality. It has enough test coverage which enables changes in implementation without the risk of functional regressions.

## Responsibility <a href="#responsibility" id="responsibility"></a>

The code takes into account its ethical obligations on data, as well as societal norms.

Responsible code is lawful, trustworthy, and respectful.

### Lawful <a href="#lawful" id="lawful"></a>

The code respects licensing and copyright regulation. It exercises the creator’s rights and honors other’s rights to license their own code.

### Trustworthy <a href="#trustworthy" id="trustworthy"></a>

The code abstains from revealing or hard-coding private information. It preserves sensitive private information such as credentials and personally identifying information.

### Respectful <a href="#respectful" id="respectful"></a>

The code refrains from using discriminatory and offensive language. It chooses to prioritize inclusive terminology whenever an alternative exists that conveys the same meaning.

## Learn more <a href="#learn-more" id="learn-more"></a>

Check the [software-qualities](https://docs.sonarsource.com/sonarqube-server/10.7/core-concepts/clean-code/software-qualities "mention") page to better understand software qualities. On the [code-analysis](https://docs.sonarsource.com/sonarqube-server/10.7/core-concepts/clean-code/code-analysis "mention") page you can learn how Clean Code attributes and software qualities are impacted by your code issue.
