More on Java Metrics
Jun. 7th, 2003 02:45 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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)