Code complexity

For questions and postings not covered by the other forums
danakrigg
Posts: 2
Joined: Thu Nov 26, 2009 10:03 pm

Code complexity

Postby danakrigg » Thu Nov 26, 2009 10:47 pm

Has anyone ever written or adopted a routine to measure code complexity for Jade?

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: Code complexity

Postby allistar » Fri Nov 27, 2009 9:46 am

What do you mean by "code complexity"? That could be defined in a number of ways. The number of lines in a single method, how an algorithm recurses, how much complicated mathematics is in it, the number of different objects touched by a method call, the number of distinct paths through a method.

A couple of years ago I developed a Jade code analyser (written in Jade) which allows you to analyse either metadata or code itself. It parses one or more Jade methods to give an abstract syntax tree (AST - essentially a hierarchical tree of objects representing the method) which you can then analyse. It can be used for simple code review, such as "does this method leak an iterator" which is a simple rule to implement. Once you had defined what is meant by "code complexity" you could then build some rules that takes the AST and determines the complexity of the code.

danakrigg
Posts: 2
Joined: Thu Nov 26, 2009 10:03 pm

Re: Code complexity

Postby danakrigg » Thu Dec 03, 2009 9:38 pm

Allistar,

What I want is a measure against the code that measures the complexity of a method/class so I can use it to limit the complexity during development.

http://en.wikipedia.org/wiki/Cyclomatic_complexity

I think this would be mainly roots through the code.

Thanks,
Dan.

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: Code complexity

Postby allistar » Mon Dec 07, 2009 7:03 am

I've had a look at that Wikipedia article and it is very interesting. I see no technical reason why the code complexity of Jade code couldn't be measured, once you have a system that can parse out code. An issue may be how inheritance effects the definition (and hence measurement) of complexity. Also, it would be difficult to measure code complexity across delivered notifications. It would be an interesting exercise to extend a parsing tool to provide a measurement for code complexity, and then introduce this into the unit testing or peer-review phase of development. The goal of which would be to reduce code compexity.

ROBOT
Posts: 2
Joined: Tue Dec 08, 2009 12:43 pm

Re: Code complexity

Postby ROBOT » Tue Dec 08, 2009 12:48 pm

Brings back COSC324 memories, If someone made a Jade app that covered all of the various SE metrics obtainable similar to the Complexity data you can get from JBuilder, I imagine it would be quite useful, Project managers would be able to get a better idea of whose got the tidiest code.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 25 guests

cron