www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Cyclomatic complexity in D ?

reply Basile B. <b2.temp gmx.com> writes:
Last night I've done a bit of documentation work on cyclomatic 
complexity. From this work it looks like the tools that do this 
static analysis are only using the AST (e.g the CC is computed 
for a each single function, and function calls inside the graph 
are considered as "connected componenents" with a constant weight 
of 1.

The problems I see with D are
- the metaprogramming features. (clearly unsolvable)
- conditional compilation: "version()" and "static if" are hardly 
handlable at the AST level, meaning that a bit of semantic is 
necessary to compute the real CC.
- functional programming, CTFE.

So what the CC for ?
- DScanner could implement it (or also the maintainability index) 
to check existing code-bases.
- As a guard, i.e when you're inspired and that you write 2000 
SLOC in the day.

So CC possible or not in D (at the AST level) ?
Aug 15 2016
next sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Monday, 15 August 2016 at 22:36:41 UTC, Basile B. wrote:
 Last night I've done a bit of documentation work on cyclomatic 
 complexity. From this work it looks like the tools that do this 
 static analysis are only using the AST (e.g the CC is computed 
 for a each single function, and function calls inside the graph 
 are considered as "connected componenents" with a constant 
 weight of 1.

 [...]
Possible - Certainly. Doable - I am not sure. But I am going to tend to no.
Aug 15 2016
parent Basile B. <b2.temp gmx.com> writes:
On Tuesday, 16 August 2016 at 00:34:36 UTC, Stefan Koch wrote:
 On Monday, 15 August 2016 at 22:36:41 UTC, Basile B. wrote:
 Last night I've done a bit of documentation work on cyclomatic 
 complexity. From this work it looks like the tools that do 
 this static analysis are only using the AST (e.g the CC is 
 computed for a each single function, and function calls inside 
 the graph are considered as "connected componenents" with a 
 constant weight of 1.

 [...]
Possible - Certainly. Doable - I am not sure. But I am going to tend to no.
I think to put a "trusting" variable into what would be the normal caclculation, for example each time a compile branch is reached while visiting the AST the trusting of the final value is reduced by a certain factor. Unfortunately I'm not a computer scientist so it'll be hard to determine the "compile time branch effect".
Aug 15 2016
prev sibling parent Basile B. <b2.temp gmx.com> writes:
On Monday, 15 August 2016 at 22:36:41 UTC, Basile B. wrote:
 Last night I've done a bit of documentation work on cyclomatic 
 complexity. From this work it looks like the tools that do this 
 static analysis are only using the AST (e.g the CC is computed 
 for a each single function, and function calls inside the graph 
 are considered as "connected componenents" with a constant 
 weight of 1.

 The problems I see with D are
 - the metaprogramming features. (clearly unsolvable)
 - conditional compilation: "version()" and "static if" are 
 hardly handlable at the AST level, meaning that a bit of 
 semantic is necessary to compute the real CC.
 - functional programming, CTFE.

 So what the CC for ?
 - DScanner could implement it (or also the maintainability 
 index) to check existing code-bases.
 - As a guard, i.e when you're inspired and that you write 2000 
 SLOC in the day.

 So CC possible or not in D (at the AST level) ?
Even detecting the main() in the AST is subject to error °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° version(set_by_command-line) { static if (modulea.a || b && modulec.c) void main(){} else void naim(){} } else { version(yo_o_yo) { static if (a || modulek.b && c) void main(){} else void naim(){} } else void nami(){} } °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° Good luck to find the main() with only the AST an no semantic ;)
Aug 15 2016