DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Culture and Methodologies
  3. Methodologies
  4. The Optional Abomination

The Optional Abomination

Programmers should look to reduce complexity whenever they can. Bringing Optional into the equation, among other choices, is a recipe for headaches.

Grzegorz Ziemoński user avatar by
Grzegorz Ziemoński
·
Jan. 20, 17 · Opinion
Like (26)
Save
Tweet
Share
13.54K Views

Join the DZone community and get the full member experience.

Join For Free

There’s this piece of code… I keep thinking about it. It shows up in my dreams. I open it every time I get to work. I learned it by heart already. It scares me. It reminds me of every bad thing that ever happened to me in my life. It reminds me of every line of crappy code that I ever wrote. It’s like a whisper in my ear: You can’t avoid me. Help! Please help!

public class PresenceCheck {
    public static boolean isPresent(Object val) {
        return Optional.ofNullable(val).isPresent();
    }
    public static boolean isNotPresent(Object val) {
        return ! isPresent(val);
    }
}


My eyes are burning! Aaarrgh! Why? Why? Why? Why? Why?!

To be honest, I knew things are going the wrong way when Java 8 came along and I saw people using Objects.isNull and Objects.nonNull instead of a normal null check, but this?!

A big part of our profession is handling complexity. We take complex domains and make software out of it. We hide the complexity between a (supposedly) nice UI, so that the end-user does not have to deal with it. Ideally, what he sees is a reflection of his mental model of the problem and he feels “at home” using our software.

I’ve made the words “complex domains” bold for a reason. The world that we’re trying to handle is complex already. This complexity needs to be then represented in the code somehow, in order to solve our user’s problem. That’s what we call inherent complexity.

Unfortunately, more often than not, there’s another kind of complexity lurking in there — accidental complexity. This is the kind of complexity that we developers create “accidentally” when coding and it’s not related to complexity of the domain itself — it’s not necessary to make the system work.

Inherent complexity mixed with accidental complexity is an extremely dangerous mixture. Drink it for too long and your system will become a legacy that you don’t want to drag along. Therefore, we have to do everything we can to limit the complexity. We want simplicity!

Now, it’s beyond a single post, probably beyond a single book and maybe even beyond a single mind to understand and explain all the ways to limit complexity in software. But whatever programming language you use, whatever framework stack you choose and whatever kind of applications you make, the first step is always the same: LEARN YOUR GOD DAMN PROGRAMMING LANGUAGE!

Read books, documentation, blogs, read the damn source code. Sometimes, it’s a matter of one click in the IDE to avoid making a fool out of yourself:

/**
 * Return {@code true} if there is a value present, otherwise {@code false}.
 *
 * @return {@code true} if there is a value present, otherwise {@code false}
 */
public boolean isPresent() {
    return value != null;
}


And you, Optional Abomination, leave me and my life, now!

Image title

IT End user Mental model Software Book

Published at DZone with permission of Grzegorz Ziemoński, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Apache Kafka vs. Memphis.dev
  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It
  • Core Machine Learning Metrics
  • Top 5 Node.js REST API Frameworks

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: