# Code Smell 162 - Too Many Parentheses

# Code Smell 162 - Too Many Parentheses
            
> TL;DR: Use as few parentheses as possible.

# Problems

- Readability

- Syntactic complexity

# Solutions

1. Remove all not necessary parentheses

# Context

We read code from left to right (at least in western culture). 

Parentheses often break this flow, adding cognitive complexity

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/03c6940b1fa140572f29bfe37cf784c1)

```javascript

schwarzschild = ((((2 * GRAVITATION_CONSTANT)) * mass) / ((LIGHT_SPEED ** 2)))

```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/5b468c4d60d25dec61e538d0c1ed1329)

```javascript

schwarzschild = (2 * GRAVITATION_CONSTANT * mass) / (LIGHT_SPEED ** 2)

```

# Detection

[X] Automatic 

This is a fully automated code smell.

It is based on syntax trees.

Many tools detect it.

# Exceptions

On some complex formulas, we can add extra parenthesis for terms readability.

# Tags

- Readability

- Bloaters

# Relations

%[https://maximilianocontieri.com/code-smell-02-constants-and-magic-numbers]

# Conclusion

We write code once and read it too many times.

Readability is king.  

# Disclaimer

Code Smells are just my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Nick Fewings](https://unsplash.com/@jannerboy62) on [Unsplash](https://unsplash.com/s/photos/signs)
  
* * *

> If someone claims to have the perfect programming language, he is either a fool or a salesman or both.

_Bjarne Stroustrup_
 
%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
