The Optional Abomination

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!

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?!

Dear Developers

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:

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

About the Author Grzegorz Ziemoński

King of Tidy Java, nerd that thinks about producing perfect software all the time and proud owner of 2 cats.

follow me on:
  • Tim

    It’s still early, but I seem to get the impression from this post that you don’t like java 8’s Optional class? If so, could you elaborate on why?

    • I love Optionals and I’m totally advocating the use of them. I just wanted to show you the scary snippet and convey a message not to fall into the new&shiny trap without thinking.
      PS. When can we expect the next article of yours? Your writings looked promising!