Cyclomatique Complexity

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Cyclomatique Complexity

abdelghani ALIDRA
Hi,

I have just noticed that when calculating the cyclomatic complexity of a method, Moose adds 1 for each boolean operator in the code.
For instance, the cyclomatique complexity of 

SomeClass>>aMethod 
^true or:false 

equals 2

This is funny because I found such a thing anywhere else. 

In addition, In the method RBVisitorForFAMIXMetrics>>computeCyclomaticNumber: there is a comment that says : 

"The score is basically the number of decision points in a routine + 1. Decision points are taken to be conditionals and loops.”

but then in the code, there is another strange comment :"-- HERE STARTS THE OLD ERRORFUL IMPL --"
and some lines further :

cyclo := self cyclomaticNumber + 1 + booleanOperators.

So my question is : Why booleanOperators is used to calculate cyclomatique complexity. Wouldn’t it be simpler to do cyclo := self cyclomaticNumber + 1?

Thanks in advance

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Cyclomatique Complexity

Stéphane Ducasse
Normally cyclo is 
the number of paths
so 

1 for the true (the main flow)
+ on for the true and the or: the alternative flow.

Stef

On 12 Nov 2017, at 18:06, Alidra Abdelghani <[hidden email]> wrote:

Hi,

I have just noticed that when calculating the cyclomatic complexity of a method, Moose adds 1 for each boolean operator in the code.
For instance, the cyclomatique complexity of 

SomeClass>>aMethod 
^true or:false 

equals 2

This is funny because I found such a thing anywhere else. 

In addition, In the method RBVisitorForFAMIXMetrics>>computeCyclomaticNumber: there is a comment that says : 

"The score is basically the number of decision points in a routine + 1. Decision points are taken to be conditionals and loops.”

but then in the code, there is another strange comment :"-- HERE STARTS THE OLD ERRORFUL IMPL --"
and some lines further :

cyclo := self cyclomaticNumber + 1 + booleanOperators.

So my question is : Why booleanOperators is used to calculate cyclomatique complexity. Wouldn’t it be simpler to do cyclo := self cyclomaticNumber + 1?

Thanks in advance
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Cyclomatique Complexity

Nicolas Anquetil


Yes typically, it is easier to count cyclomatic as +1 for each "testing statement" (if, loops)

May be the rational is that #or: is basically the same thing as #ifFalse: and #and: is similar to #ifTrue: ?

In FAST for pharo, there is an algorithm that computes cyclomatic also, it uses the same ideas (#or: and #and: add 1 to cyclomatic)

nicolas


On 12/11/2017 18:11, Stéphane Ducasse wrote:
Normally cyclo is 
the number of paths
so 

1 for the true (the main flow)
+ on for the true and the or: the alternative flow.

Stef

On 12 Nov 2017, at 18:06, Alidra Abdelghani <[hidden email]> wrote:

Hi,

I have just noticed that when calculating the cyclomatic complexity of a method, Moose adds 1 for each boolean operator in the code.
For instance, the cyclomatique complexity of 

SomeClass>>aMethod 
^true or:false 

equals 2

This is funny because I found such a thing anywhere else. 

In addition, In the method RBVisitorForFAMIXMetrics>>computeCyclomaticNumber: there is a comment that says : 

"The score is basically the number of decision points in a routine + 1. Decision points are taken to be conditionals and loops.”

but then in the code, there is another strange comment :"-- HERE STARTS THE OLD ERRORFUL IMPL --"
and some lines further :

cyclo := self cyclomaticNumber + 1 + booleanOperators.

So my question is : Why booleanOperators is used to calculate cyclomatique complexity. Wouldn’t it be simpler to do cyclo := self cyclomaticNumber + 1?

Thanks in advance
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France



_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

-- 
Nicolas Anquetil
RMod team -- Inria Lille

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Cyclomatique Complexity

Fuhrmanator
It seems to make sense to me if you think of code optimization (I assume Pharo does this). Indeed

^true :or false 

must always execute both paths, but 

^false :or true 

only needs to execute one path to have a result of true for the OR. There's a similar case for :and with false values.  


On Tue, Nov 14, 2017 at 4:17 AM, Nicolas Anquetil <[hidden email]> wrote:


Yes typically, it is easier to count cyclomatic as +1 for each "testing statement" (if, loops)

May be the rational is that #or: is basically the same thing as #ifFalse: and #and: is similar to #ifTrue: ?

In FAST for pharo, there is an algorithm that computes cyclomatic also, it uses the same ideas (#or: and #and: add 1 to cyclomatic)

nicolas


On 12/11/2017 18:11, Stéphane Ducasse wrote:
Normally cyclo is 
the number of paths
so 

1 for the true (the main flow)
+ on for the true and the or: the alternative flow.

Stef

On 12 Nov 2017, at 18:06, Alidra Abdelghani <[hidden email]> wrote:

Hi,

I have just noticed that when calculating the cyclomatic complexity of a method, Moose adds 1 for each boolean operator in the code.
For instance, the cyclomatique complexity of 

SomeClass>>aMethod 
^true or:false 

equals 2

This is funny because I found such a thing anywhere else. 

In addition, In the method RBVisitorForFAMIXMetrics>>computeCyclomaticNumber: there is a comment that says : 

"The score is basically the number of decision points in a routine + 1. Decision points are taken to be conditionals and loops.”

but then in the code, there is another strange comment :"-- HERE STARTS THE OLD ERRORFUL IMPL --"
and some lines further :

cyclo := self cyclomaticNumber + 1 + booleanOperators.

So my question is : Why booleanOperators is used to calculate cyclomatique complexity. Wouldn’t it be simpler to do cyclo := self cyclomaticNumber + 1?

Thanks in advance
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

--------------------------------------------
Stéphane Ducasse
03 59 35 87 52
Assistant: Julie Jonas 
FAX 03 59 57 78 50
TEL 03 59 35 86 16
S. Ducasse - Inria
40, avenue Halley, 
Parc Scientifique de la Haute Borne, Bât.A, Park Plaza
Villeneuve d'Ascq 59650
France



_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev

-- 
Nicolas Anquetil
RMod team -- Inria Lille

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev



_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.list.inf.unibe.ch/listinfo/moose-dev