Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / MATLAB / July 2008



Tip: Looking for answers? Try searching our database.

Cyclomatic complexity also

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matt Fig - 15 Jul 2008 18:58 GMT
Hello,

There is another thread about C.C. going, so rather than
hijack it I will start another.
Can someone show me by example what this is really about?  I
am especially interested in how this relates to code length.
I want to see a short code with high C.C., if that's
possible.  For example, say for simplicity:

Score = CC(fcn)/numlines(fcn)

What is the highest SCORE that can be achieved on purpose?
I think this might help me understand this metric.  Thanks.
Kenneth Eaton - 15 Jul 2008 19:19 GMT
"Matt Fig" <spamanon@yahoo.com> wrote in message
<g5iofa$pnv$1@fred.mathworks.com>...
> Hello,
>
[quoted text clipped - 9 lines]
> What is the highest SCORE that can be achieved on purpose?
> I think this might help me understand this metric.  Thanks.

I think it is related to the number of if-else branches
that you have in your code. Also, in my experience, switch
statements can increase CC quite a bit, especially if there
are many switch cases, a lot of code within each switch
(with if-elses), or switches inside switches.

Ken
Markthomas - 15 Jul 2008 19:37 GMT
"Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in
message <g5ipml$adk$1@fred.mathworks.com>...
> "Matt Fig" <spamanon@yahoo.com> wrote in message
> <g5iofa$pnv$1@fred.mathworks.com>...
[quoted text clipped - 23 lines]
>
> Ken

In my case i have 55 cases for switch-case  but 11 cases
are controlled by 7 different functions and the other 44
cases are controlled by 4 differnt functions.  I guess i
can see how i got such a high result!
Kenneth Eaton - 15 Jul 2008 20:17 GMT
> In my case i have 55 cases for switch-case  but 11 cases
> are controlled by 7 different functions and the other 44
> cases are controlled by 4 differnt functions.  I guess i
> can see how i got such a high result!

Wow, 55 switch cases is a lot. The most I had was 10-12
switch cases, with a lot of if-else laden code for each
case, and I got CCs around the low 30s.

Ken
Markthomas - 15 Jul 2008 20:27 GMT
"Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in
message <g5it3g$hv0$1@fred.mathworks.com>...

> > In my case i have 55 cases for switch-case  but 11 cases
> > are controlled by 7 different functions and the other 44
[quoted text clipped - 6 lines]
>
> Ken

do you think if i change the switch case to if then i will
get a better CC number?
Kenneth Eaton - 15 Jul 2008 20:42 GMT
"Markthomas " <uebermenchens@yahoo.com> wrote in message
<g5itm5$p56$1@fred.mathworks.com>...
> "Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in
> message <g5it3g$hv0$1@fred.mathworks.com>...
[quoted text clipped - 15 lines]
> do you think if i change the switch case to if then i will
> get a better CC number?

I'm not totally sure what you mean when you say the cases
are "controlled" by a certain number of functions. Do you
have a lot of cases that encompass the exact same set of
commands? If so, you can simplify this way:

Original switch:

switch stringValue,
 case 'a',
   myfcn1;
 case 'b',
   myfcn1;
 case 'c',
   myfcn1;
 ...(other cases)...
end

New switch:

switch stringValue,
 case {'a' 'b' 'c'},
   myfcn1;
 ...(other cases)...
end

I imagine this might help the CC score. Also, you can use
the "otherwise" option for switch statements, which catches
all other possibilities besides those you explicitly list
as cases:

switch stringValue,
 case 'a',
   myfcn1;
 case 'b',
   myfcn2;
 otherwise,
   myfcn3;
end

Hope that helps,
Ken
Markthomas - 15 Jul 2008 22:22 GMT
"Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in
message <g5iuia$7d4$1@fred.mathworks.com>...
> "Markthomas " <uebermenchens@yahoo.com> wrote in message
> <g5itm5$p56$1@fred.mathworks.com>...
[quoted text clipped - 62 lines]
> Hope that helps,
> Ken

you are exactly right!  Thanks i will try it out and post
the results!!
Markthomas - 15 Jul 2008 22:41 GMT
"Markthomas " <uebermenchens@yahoo.com> wrote in message
<g5j4dp$bst$1@fred.mathworks.com>...
> "Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in
> message <g5iuia$7d4$1@fred.mathworks.com>...
[quoted text clipped - 71 lines]
> you are exactly right!  Thanks i will try it out and post
> the results!!

one reason why it won't  work for maybe 47 of the cases
because the function outputs control all the variables such
that each of the variables don't get mixed up... to get
this to work i need to create indexed variables such that
when i go through fcn1 the first time it outputs:

BFL1 = BFL where BFL is <Yx1> vector

then the second time it is
BFL2 = BFL where BFL is <Vx1>

i still can't get that problem right either!
Peter Boettcher - 16 Jul 2008 13:54 GMT
> one reason why it won't  work for maybe 47 of the cases
> because the function outputs control all the variables such
> that each of the variables don't get mixed up...

I can't understand that..

> to get this to work i need to create indexed variables such that when
> i go through fcn1 the first time it outputs:
[quoted text clipped - 5 lines]
>
> i still can't get that problem right either!

Use cell arrays

BFL{1} = BFL;
BF2{2} = BFL;

Or,

for i=1:10
 BFL{i} = some_function_that_generates_BFL;
end

-Peter
Markthomas - 16 Jul 2008 19:14 GMT
Peter Boettcher <boettcher@ll.mit.edu> wrote in message
<muyskuarnu7.fsf@G99-Boettcher.llan.ll.mit.edu>...

> > one reason why it won't  work for maybe 47 of the cases
> > because the function outputs control all the variables such
[quoted text clipped - 24 lines]
>
> -Peter

I removed about 6 of the cases and it brought the CC down
to 51 i am going to adjust the rest of my code to get the
rest of the CC out!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.