Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C function only called once and cyclomatic complexity

I think this question is more about style: I have an algorithm that has a very high CC (and a lot of lines!). I want to reduce it, and it's easy since there are pieces of code that can be grouped. The problem is that doing things this way I would have a "big" function calling "small" functions which are only called once.

In my opinion breaking a big function in small pieces is better for the legibility of the code (in this case) despite functions are called once.

What do you thik? How do yo do in similar cases?

like image 329
Schopenhauer Avatar asked Dec 17 '22 00:12

Schopenhauer


1 Answers

Breaking a big function into smaller, mostly separate chunks is a perfectly good idea. It makes the code more readable and the control flow more clear.

If the functions are static and called only once, the compiler will probably inline them for you without even being asked, so there's no need to worry about runtime cost.

like image 106
Thomas Avatar answered Feb 19 '23 21:02

Thomas