There’s a certain class of bad code we’ve all seen before:

boolean someFunction() {
    if (someBooleanExpression) {
        return true;
    } else {
        return false;
    }
}

It’s dumb, but largely harmless. We’ve posted variations on this idea in the past. Scott P, however, found a new variation that may be the pinnacle of this kind of simple-minded programming. I’ll let him introduce it.

I inherited a project that was developed in isolation by a lone developer that didn’t do code reviews. I find something new to be horrified about every day. The developer responsible has a knack for adding unnecessary complexity to what should have been a much simpler application. This method perfectly sums up what the architecture of this application is like on every level. It’s layer upon layer of obfuscation or redundant code.

boolean hasFeatures() {
        if (license.getFeatures().size() > 0 ? true : false) {
                return true;
        }
        return false;
}

Honestly, I think the ternary operator doesn’t get enough use. We should just start putting ternary expressions all over our code, even if it means writing things like: myvar = true ? valueReturningFunction() : valueReturningFunction();. Isn’t that pretty great? I love it.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!