bcholmes: (Default)
BC Holmes ([personal profile] bcholmes) wrote2003-06-07 02:45 pm

More on Java Metrics

I assert that the following methods are identical in terms of cyclomatic complexity.

Version A:


public String getFullName() {
    String name;
    if (this.fullName == null) {
        name = getFirstName() + " " + getLastName();
    } else {
        name = this.fullName;
    }
    return name;
}

Version B:


public String getFullName() {
    if (this.fullName == null) {
        return getFirstName() + " " + getLastName();
    } else {
        return this.fullName;
    }
}

Version C:


public String getFullName() {
    return (this.fullName == null) ? (getFirstName() + " " + getLastName()) : this.fullName;
}

Most cyclomatic complexity counters that I've seen claim that Version A has a cyclomatic complexity of 2, version B has a cyclomatic complexity of 3 or 4 and version C has a cyclomatic complexity of 1. I claim that they all have a cyclomatic complexity of 2.

Right...

[identity profile] smurfix.livejournal.com 2003-07-06 01:41 am (UTC)(link)
Your claim seems to be correct. Time to file a couple of bug reports. ;-)