DEV Community

Cover image for Thinking twice before writing IF
Saurabh Ramesh Kacholiya
Saurabh Ramesh Kacholiya

Posted on • Edited on

Thinking twice before writing IF

Recently I come across a very healthy discussion with my manager about writing IF condition

so whenever you are writing if condition as a developer we open a decision tree (for example yes and no) and when the codebase increases more branching of decisions paths are introduced in the code resulting in difficulty to read and debug the code.

To avoid we can use Composition where we are directly passing the render component to child components from the parent as shown in the above image. This way we are also using dumb components to avoid side effects in the children components.

PS. I know it is not worthy to replace every IF the condition from your codebase. I also don't do that. that is why the blog title is Thinking twice before writing if and still, you feel you cant work without if go on use IF condition

Top comments (0)