Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 72133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:59:49+00:00 2026-05-10T19:59:49+00:00

Recently our company has started measuring the cyclomatic complexity (CC) of the functions in

  • 0

Recently our company has started measuring the cyclomatic complexity (CC) of the functions in our code on a weekly basis, and reporting which functions have improved or worsened. So we have started paying a lot more attention to the CC of functions.

I’ve read that CC could be informally calculated as 1 + the number of decision points in a function (e.g. if statement, for loop, select etc), or also the number of paths through a function…

I understand that the easiest way of reducing CC is to use the Extract Method refactoring repeatedly…

There are somethings I am unsure about, e.g. what is the CC of the following code fragments?

1)

for (int i = 0; i < 3; i++)     Console.WriteLine('Hello'); 

And

Console.WriteLine('Hello'); Console.WriteLine('Hello'); Console.WriteLine('Hello'); 

They both do the same thing, but does the first version have a higher CC because of the for statement?

2)

if (condition1)     if (condition2)         if (condition 3)             Console.WriteLine('wibble'); 

And

if (condition1 && condition2 && condition3)     Console.WriteLine('wibble'); 

Assuming the language does short-circuit evaluation, such as C#, then these two code fragments have the same effect… but is the CC of the first fragment higher because it has 3 decision points/if statements?

3)

if (condition1) {     Console.WriteLine('one');      if (condition2)         Console.WriteLine('one and two'); } 

And

if (condition3)     Console.WriteLine('fizz');  if (condition4)     Console.WriteLine('buzz'); 

These two code fragments do different things, but do they have the same CC? Or does the nested if statement in the first fragment have a higher CC? i.e. nested if statements are mentally more complex to understand, but is that reflected in the CC?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:59:49+00:00Added an answer on May 10, 2026 at 7:59 pm
    1. Yes. Your first example has a decision point and your second does not, so the first has a higher CC.
    2. Yes-maybe, your first example has multiple decision points and thus a higher CC. (See below for explanation.)
    3. Yes-maybe. Obviously they have the same number of decision points, but there are different ways to calculate CC, which means …

    … if your company is measuring CC in a specific way, then you need to become familiar with that method (hopefully they are using tools to do this). There are different ways to calculate CC for different situations (case statements, Boolean operators, etc.), but you should get the same kind of information from the metric no matter what convention you use.

    The bigger problem is what others have mentioned, that your company seems to be focusing more on CC than on the code behind it. In general, sure, below 5 is great, below 10 is good, below 20 is okay, 21 to 50 should be a warning sign, and above 50 should be a big warning sign, but those are guides, not absolute rules. You should probably examine the code in a procedure that has a CC above 50 to ensure it isn’t just a huge heap of code, but maybe there is a specific reason why the procedure is written that way, and it’s not feasible (for any number of reasons) to refactor it.

    If you use tools to refactor your code to reduce CC, make sure you understand what the tools are doing, and that they’re not simply shifting one problem to another place. Ultimately, you want your code to have few defects, to work properly, and to be relatively easy to maintain. If that code also has a low CC, good for it. If your code meets these criteria and has a CC above 10, maybe it’s time to sit down with whatever management you can and defend your code (and perhaps get them to examine their policy).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Your example updated and working. I don't know what you… May 11, 2026 at 3:37 pm
  • added an answer How about this? option 2: begin tran; delete from tablea… May 11, 2026 at 3:37 pm
  • added an answer What you are describing is integration testing. What integration testing… May 11, 2026 at 3:37 pm

Related Questions

My company has recently started using Scrum; we've done 2 sprints. We're still learning,
My company has recently started developing custom iPhone applications for various clients. One of
In our infrastructure, we have lots of little Java projects built by Maven2. Each
I have reviewed DashCommerce, nopCommerce and DotShoppingCart for possible use and all of them

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.