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.


Post a comment in response:

This account has disabled anonymous posting.
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org