Option Types vs Nulls

This cluster debates the superiority of explicit Option/Optional/Maybe types over traditional null pointers or nullable types in languages like Rust, Kotlin, Swift, and Haskell, emphasizing type safety, compile-time checks, and handling of absent values.

📉 Falling 0.4x Programming Languages
1,944
Comments
18
Years Active
5
Top Authors
#5745
Topic ID

Activity Over Time

2009
8
2010
10
2011
14
2012
22
2013
70
2014
107
2015
150
2016
97
2017
118
2018
211
2019
91
2020
237
2021
200
2022
164
2023
173
2024
148
2025
115
2026
9

Keywords

e.g safety.html UB IMO TypeScript JS kotlinlang.org ADT NULL BTW null nullable option optional type types pointer rust language languages

Sample Comments

realharo Jan 25, 2017 View on HN

Is there something that you can express with Option that you cannot express with a nullable type?

chris_overseas Mar 9, 2025 View on HN

Not entirely true - e.g. Kotlin has null safety built into its type system, and I find it much nicer than the option/optional approaches used in various other languages.https://kotlinlang.org/docs/null-safety.html

iopq Apr 9, 2014 View on HN

Consider the following: some languages don't have null. When you need nullable what you really want is an Option/Maybe type. No null pointer exceptions, ever! It just won't compile until you fix the bug.

valbaca Jul 15, 2022 View on HN

Rust has Option which you opt-into for cases like the one you describe.What's special is that it's not like Go/Java/JS/etc where *every* pointer/reference can be null, so you have to constantly be on guard for it.If I give you a Thing in Rust, you know it's a Thing and can use it as a Thing. If I give you an Option then you know that it's either a Some or None.If I give you a Thing in Go/Java/etc well, it could b nil. Java h

RX14 May 10, 2018 View on HN

You don't need option types for the compiler to enforce safety around nulls. Its possible to model null as its own type in the type system to enforce safety.

TeeWEE Mar 13, 2023 View on HN

I dont think this is true for the nullability type... Which are in essence compile time optionals... Without the overhead.

quickthrower2 May 26, 2019 View on HN

Get rid of retched compulsory nullability and offer optionally optional types. Could be via ADT style Maybe a = Just a | Nothing, or just a language feature eg Mytype vs Mytype?

int_19h Apr 7, 2025 View on HN

It's not so much Optional that deals with the bug. It's the fact that you can't just use a value that could possibly be null in a way that would break at runtime if it is null - the type system won't allow you, forcing an explicit check. Different languages do this in different ways - e.g. in C# and TypeScript you still have null, but references are designated as nullable or non-nullable - and an explicit comparison to null changes the type of the corresponding variable to in

people should really try non-nullable types in typescript and kotlin, in addition to smart-casting. Then they would realize optionals are niche and cumbersome.

tmpfs Dec 8, 2020 View on HN

This comment is misleading. They may appear to be the same but they are not because in certain languages (like Rust) you are forced to handle the `Option` case when a value is `None` which guides a programmer's thinking in the direction of what to do in that situation.Without these higher level types runtime null pointer exceptions are very common, using `Option` or `Maybe` creates a situation where these sorts of errors are a lot less likely.