logoalt Hacker News

diarrheatoday at 7:39 AM3 repliesview on HN

This is the mess a language lands on when it conflates optionality (a semantic concept) with references/pointers (purely a machine concept). In Go, the requirement "need (non-optional) a reference to an object" is simply not expressible. This is a solved problem in other languages, for example `&T` vs. `Option<&T>` in Rust.


Replies

Groxxtoday at 8:02 AM

Don't forget mutability! Go throws that on top too.

Animatstoday at 8:08 AM

In C++, that distinction supposedly exists. References should never be null, while pointers can be. But there's no enforcement.

    int& ref = *ptr;
ought to generate a panic for a null pointer. But it doesn't. They were so close to getting it right.
show 4 replies
throwa356262today at 7:53 AM

What the article said applies to Rust ref vs ref-option too.

show 1 reply