Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Handling Null in Functional Programming

Evelyn Masso
February 02, 2019

Handling Null in Functional Programming

Nulls are a fact of life—sometimes a value can be absent, which is important information to have However if a variable can be null, we often have to write extra code to handle that possibility. How can we utilize functional, typed languages to only allow null where it communicates important information and eliminate it everywhere else? This talk will identify patterns to do just that and discuss how they can help shape your application’s architecture.

Given at Empex LA (http://empex.co/la.html)

Evelyn Masso

February 02, 2019
Tweet

More Decks by Evelyn Masso

Other Decks in Programming

Transcript

  1. When to use null • when something can optionally exist

    • instead of using a number (like -1) or a boolean type union • for data structures (but then check for it as soon as possible in business logic)
  2. When to avoid null? • there are multiple ways something

    can not exist (that you care about) • future proofing your data model
  3. enum People { Peeta, Gale, Hermione, } explicit cases enum

    Options { NoOne, SomeoneElse, Unknown }
  4. default values enum Dates = { Peeta, Gail, Hermione, None

    } type Availables = Dates function(date: Availables = Dates.None) { // do something }