Today I come to share a little tip to improve the readability of our code. We will achieve this by using guard clauses which will help us avoid this IF nesting.
Examples
Bad ❌
In this example, we can see how and IF nesting appears, in this case, it is a simple example but this can get complicated, with each nesting that is added the code will become less readable and therefore less friendly and less maintainable.
Good ✅
Using guard clauses we avoid the nesting of IF conditionals since we will "first control the error cases", and then we will continue with our logic.
Conclusion
Using guard clauses is good practice to avoid unnecessary ramifications and therefore make your code easier and more readable. If we apply these guidelines we will make our software much more maintainable and friendly.
Thanks for reading me. 😊