Nothing is better than the Optional type

*
Proposal
Short Form
Intermediate

Excerpt

Optional should be prohibited: it is an overreaction to a problem that already has an elegant solution.

Description

Many programming languages have a typed named Optional, which is a container that is either empty or contains a non-null value. The Web and blogosphere are full of claims that the Optional class solves the problem of null pointer exceptions. This is not true. In this talk, you will learn that Optional has numerous problems without countervailing benefits. Optional does not make your code more correct or robust. However, Optional does have these effects:

  • It transforms a NullPointerException into a NoSuchElementException, which still crashes your program.
  • It creates new problems that were not a danger before.
  • It clutters your code.
  • It adds both space and time overheads.

Because of Optional’s problems, many commentators advise programmers to use Optional only in very limited situations, such as only as return types. This denies the programmer the alleged benefits of Optional everywhere else in the program.

The Optional type isn’t all bad: it does enables code reduction when dealing with possibly-present data, but this can be achieved in other ways. We will also discuss other arguments in favor of Optional.

There is a real problem that Optional tries to solve: accidentally forgetting to check all the possibilities when processing data. This talk shows a better way to avoid such problems, without the overheads and new problems of Optional.

Speaking experience

Michael Ernst has given dozens of talks to tens of thousands of developers. His well-received presentations have made him a two-time JavaOne Rock Star. This is a new talk.

Speaker

  • Mernst headshot

    Michael Ernst

    University of Washington

    Biography

    Michael D. Ernst is a Professor in the Computer Science & Engineering department at the University of Washington.

    Ernst’s research aims to make software more reliable, more secure, and easier (and more fun!) to produce. His primary technical interests are in software engineering, programming languages, type theory, security, program analysis, bug prediction, testing, and verification. Ernst’s research combines strong theoretical foundations with realistic experimentation, with an eye to changing the way that software developers work.

    Ernst is an ACM Fellow (2014) and received the inaugural John Backus Award (2009) and the NSF CAREER Award (2002). His research has received an ICSE Most Influential Paper Award (2017), an ACM SIGSOFT Impact Paper Award (2013), 8 ACM Distinguished Paper Awards (FSE 2014, ISSTA 2014, ESEC/FSE 2011, ISSTA 2009, ESEC/FSE 2007, ICSE 2007, ICSE 2004, ESEC/FSE 2003), an ECOOP 2011 Best Paper Award, honorable mention in the 2000 ACM doctoral dissertation competition, and other honors. In 2013, Microsoft Academic Search ranked Ernst #2 in the world, in software engineering research contributions over the past 10 years. In 2016, AMiner ranked Ernst #3 among all software engineering researchers ever.

    Dr. Ernst was previously a tenured professor at MIT, and before that a researcher at Microsoft Research.

    More information is available at his homepage: http://homes.cs.washington.edu/~mernst/.

    Sessions