Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java: Complexity Measurement

Because complexity depends on many variable human characteristics, achieving automatic complexity measurement is probably hopeless. We are therefore left largely with a number of best practices which do a reasonable job of suggesting ways to avoid complexity.

Flow Complexity

A major contribution to complexity (or simplicity) is the organization of program flow. Simplifying control flow was the prime motivation for Structured Programming, which can be summarized most simply, but not esspecially comprehensibly, as the elimination of the goto statement. The ideals of structured programming have been so completely incorporated in modern programming that some newer languages, eg Java, don't even have the goto statement. The Java designers must have thought leaving out goto was risky because goto is still reserved as a keyword, but is not used.

MacCabe proposed measuring flow complexity of a function (method) as the number of decision points. His algorithm is to count 1 for just entering the method, plus one for each if, for, while, do-while, case, &&, and ||. To update his measure for Java we should also add 1 for each ?: operator, catch statement, and default clause.

Break up complex methods. A MacCabe complexity under 5 is good, from 5-10 is ok, and over 10 is too complex. A high flow complexity may also be a symptom of a function which does too much and has low cohesion. But don't take these numbers too seriously -- you may have comprehensible control flow despite high numbers, eg generated by one large case statement. But how do you simplify a method? Presumably all decisions have to be made. You simplify a method by breaking it into two or more methods, so the complexity, the demands on the human to keep many things in their mind at the same time, are reduced.

Other measures of complexity

There are many other measures of complexity: number of operators, number of lines of code, nesting depth, distance between variable references, etc.

To Do

[When time permits I'll add links to some of the automated tools for measuring Java complexity.]
Ask programming questions?

 

 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]