15 lines
824 B
Plaintext
15 lines
824 B
Plaintext
![]() |
Reducing cognitive complexity can be challenging. +
|
||
|
Here are a few suggestions:
|
||
|
|
||
|
* **Extract complex conditions in a new function.** +
|
||
|
Mixed operators in condition will increase complexity.
|
||
|
Extracting the condition in a new function with an appropriate name will reduce cognitive load.
|
||
|
* **Break down large functions.** +
|
||
|
Large functions can be hard to understand and maintain.
|
||
|
If a function is doing too many things, consider breaking it down into smaller, more manageable functions.
|
||
|
Each function should have a single responsibility.
|
||
|
* **Avoid deep nesting by returning early.** +
|
||
|
To avoid the nesting of conditions, process exceptional cases first and return early.
|
||
|
* **Use null-safe operations (if available in the language).** +
|
||
|
When available the `.?` or `??` operator replaces multiple tests and simplifies the flow.
|