Regarding McCabe's Cyclomatic Complexity

S

sam_cit

Hi,

I came to read this particular statement with respect to reducing the
complexity of a code,

The usage of functional maps matrices instead of switch statements
should be considered.

I didn't understand what the term functional maps matrices mean? and
for people who are not aware of McCabe's Cyclomatic Comlexity tool,
here is a link with a simple explaination,

http://www.teaminabox.co.uk/downloads/metrics/descriptions/CyclomaticComplexity.html

Kindly reply as soon as possible.
 
V

Vladimir S. Oka

(e-mail address removed) opined:
Hi,

I came to read this particular statement with respect to reducing
the complexity of a code,

The usage of functional maps matrices instead of switch statements
should be considered.

I didn't understand what the term functional maps matrices mean? and
for people who are not aware of McCabe's Cyclomatic Comlexity tool,
here is a link with a simple explaination,
http://www.teaminabox.co.uk/downloads/metrics/descriptions/CyclomaticComplexity.html

This is a general algorithm, rather than a C question. It is best asked
in comp.programming


--
There was a young girl of Cape Town
Who usually fucked with a clown.
He taught her the trick
Of sucking his prick,
And when it went up -- she went down.

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
 
S

sam_cit

Its here because iam more concerned with c switch statements...I just
want to understand the term functional maps matrices...
 
V

Vladimir S. Oka

(e-mail address removed) opined:
Its here because iam more concerned with c switch statements...I just
want to understand the term functional maps matrices...

Read the link in my sig before posting again, and quote context.

C language knows not of "functional map matrices" so posting here will
certainly not help you understand them.

As for the C `switch` statements, if you have a specific question about
them, do ask it here. Being "concerned" about them does not constitute
a question, though.
 
J

jacob navia

(e-mail address removed) a écrit :
Hi,

I came to read this particular statement with respect to reducing the
complexity of a code,

The usage of functional maps matrices instead of switch statements
should be considered.

I didn't understand what the term functional maps matrices mean? and
for people who are not aware of McCabe's Cyclomatic Comlexity tool,
here is a link with a simple explaination,

http://www.teaminabox.co.uk/downloads/metrics/descriptions/CyclomaticComplexity.html

Kindly reply as soon as possible.

Maybe the meaning is the following:

Any switch statement can be replaced with a table (matrix) of
two columns:

In the first column we have the keys, or values in the "case" statement,
in the second we have the code associated with the key. If we would do
that in standard C we would have to define a function for each case
statement since we can't put labels in a table, at least in standard c.

This means that you replace the switch statement by a table lookup.

Since McCabe complexity measures the branching in a procedure, a switch
statement means (at least conceptually) a branch for each case
statement. In many compilers, more branches are generated internally in
the assembly code, but that is not considered by most implementations of
the complexity metric.

jacob
 
K

Keith Thompson

[snip]

You might want to consider tweaking your signature generator.
Four-letter words don't bother me very much, but some people are
likely to be offended.
 
E

Ed Prochak

jacob said:
(e-mail address removed) a écrit :

Maybe the meaning is the following:

Any switch statement can be replaced with a table (matrix) of
two columns:

In the first column we have the keys, or values in the "case" statement,
in the second we have the code associated with the key. If we would do
that in standard C we would have to define a function for each case
statement since we can't put labels in a table, at least in standard c.

This means that you replace the switch statement by a table lookup.

Since McCabe complexity measures the branching in a procedure, a switch
statement means (at least conceptually) a branch for each case
statement. In many compilers, more branches are generated internally in
the assembly code, but that is not considered by most implementations of
the complexity metric.

jacob

Since the McCabe metric is a measure of SOURCE CODE complexity, the
generated code is irrelevant. But often the switch() statement compiles
to a jump table so the number of branches can sometimes be less that
the equivalent count of cases.


Ed
 
J

Julian V. Noble

Hi,

I came to read this particular statement with respect to reducing the
complexity of a code,

The usage of functional maps matrices instead of switch statements
should be considered.

I didn't understand what the term functional maps matrices mean? and
for people who are not aware of McCabe's Cyclomatic Comlexity tool,
here is a link with a simple explaination,

http://www.teaminabox.co.uk/downloads/metrics/descriptions/CyclomaticComplexity.html

Kindly reply as soon as possible.

I expect, that as someone else has noted, the term "functional maps
matrices" refers to the table or matrix representation of a finite
state machine. Basically the column headings are inputs that the FSM
acts on, and the row labels are the possible states of the machine.
Each cell of the matrix contains an action to perform and a transition
to some other state. Suppose I want to read in a number with a decimal
point, but I want to note an error if there is either some character
other than a digit, or a second decimal point before the number is
fully entered: in an obvious notation the matrix would look like

input: other dp digit
state | ------------------------------------------
---------------------------------------------------
0 | error1 >2 | accept >1 | accept >0
1 | error1 >2 | error2 >3 | accept >1
2 \\ abnormal termination -- bad char
3 \\ abnormal termination -- two dp's

Changing the state label to 2 or 3 is a convenience for tracing
which kind of error was made and deciding what to do at that point.

There are even (simple) ways to include counts so that no more
than a certain number of digits are accepted, etc.

The above is easily implemented in C (with switch), Forth, Lisp or
any object-oriented language. It can even be done without excess
trouble in Fortran or Basic using computed or assigned GOTO's.

--
Julian V. Noble
Professor Emeritus of Physics

http://galileo.phys.virginia.edu/~jvn/

"For there was never yet philosopher that could endure the
toothache patiently."

-- Wm. Shakespeare, Much Ado about Nothing. Act v. Sc. 1.
 
V

Vladimir S. Oka

Keith Thompson opined:
[snip]

You might want to consider tweaking your signature generator.
Four-letter words don't bother me very much, but some people are
likely to be offended.

Ooops! Apologies to anyone offended. I tought I told it not to do that.
I'll go double check now. Sorry again, it wasn't intended.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top