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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay