DriftScript
Documentation

Rationale

Why there is no null

What an option costs, and what it buys that a nullable reference cannot.

Why is there no null?

Because a nullable reference cannot tell an absence that was decided from one that was never filled in, and almost every interesting failure in a running world is the second wearing the clothes of the first. An option is a different type rather than a different value, so the question has to be answered before the value can be reached.

The half most languages skip

Adding an option type is easy. Refusing the implicit conversion into it is the part that matters and the part that annoys people: returning 1 where f32? was declared is an error here, and some(1) is what was meant. A language that accepted the first has reinvented implicit null in the other direction, because now a bare value and a present option look identical at the call site.

// Deliberately refused.
//
// A bare value does not flow into an option position. `return 1` from a function returning `f32?`
// is an error, and `return some(1)` is what was meant. A language that accepted the first has
// reinvented implicit null in the other direction: a reader can no longer tell an absence that
// was decided from one that was never filled in.

fn find(present: bool) -> f32? {
    if present {
        return 1
    } else {
        return none
    }
}

What it costs

Noise, in the places where absence is genuinely rare. A chain of three lookups that can each fail is three `if let` blocks or a propagation operator, where a nullable language would let you write the happy path and find out later. That is a real cost and it is paid on every file, in exchange for never paying the other one.