Optional - The Mother of All Bikesheds by Stuart Marks
Why Hacker News recommends it
Cited as the authoritative explanation, from the person who added it to OpenJDK, of Optional's narrow intended purpose.
What it is
Stuart Marks explains the intended purpose and proper use of Java 8's Optional class and why it caused so much controversy. He gives guidelines for using its small API correctly.
Recommended by 0 HN commenters across 0 different months, 2019 to 2022.
What Hacker News said
Cites kjeetgill · 2019-06 · on “Takes: Java web framework without static methods or annotations”
That's not really "why" it was introduced. Optional is used as a null wrapper in other JVM languages so that idiom bled over pretty naturally. Here's a talk "Optional - Mother of all Bikesheds" by Stuart Marks, the guy who added it to OpenJDK: [this video] It was mostly just meant to cover the zero or one case on fluent-style interfaces like the Streams API, so check as getFirst() or getAny(). In hindsight, the name Optional was a poor choice if they didn't want the idiom coming over.
Cites emccue · 2022-06 · on “What I miss in Java, the perspective of a Kotlin developer”
These are pretty weak arguments For the first point - val/var "More importantly, it doesn’t offer its immutable counterpart, val. You still need to add the final keyword, which nearly nobody uses." This super undermines the criticism. "It has the feature but people don't use it" isn't exactly much to write home about. Just use `final var` if you want. Make "final var over var" the same force culturally as JS's const over let" "However, the developers of Optional designed it for return values only. Nothing is available in the language syntax for methods parameters and return values. To cope with this, a bunch of libraries provides compile-time annotations:" This flow of causality here is slig
Cites cratermoon · 2022-07 · on “Rust should not have provided `unwrap`”
See also the discussion for a similar feature in Java, from "Optional: The Mother of all Bikesheds", where the use and misuse of get() has a central role. video: [this video] slides: [LINK]