bcholmes: (Default)
[personal profile] bcholmes

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...

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

Profile

bcholmes: (Default)
BC Holmes

February 2025

S M T W T F S
      1
2345678
9101112131415
16171819202122
2324252627 28 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Powered by Dreamwidth Studios