DEV Community

Shailen Naidoo
Shailen Naidoo

Posted on

Determining the number of "if" statements in your codebase

Think of conditional statements as if they are bombs waiting to go off. It might be a great metric for the team to identify how many conditional statements are being introduced into the system or how many have been removed.

I wrote a simple bash command using the popular grep and wc tools found natively in most bash implementations to scan my source code and identify the number of conditional statements.

grep -rni --exclude-dir="node_modules" "if (" * | wc -l
Enter fullscreen mode Exit fullscreen mode

Having a number for people to see gives them an idea of the general complexity or branches within an application. I believe that reducing this number should be a general goal of a software development team.

Top comments (0)