3 ms·
It says `Option<~T>` is now represented as a nullable pointer. Does that mean they introduced more prevalent nulls into the language? that seems like a sh
by tkellogg 13y ago
It says
`Option<~T>` is now represented as a nullable pointer.
Does that mean they introduced more prevalent nulls into the language? that seems like a shockingly bad choice
- kibwen 13y agoNo, it means that at runtime the representation of `Option<~T>` is simply a nullable pointer (this is also how borrowed pointers are represented at runtime, i.e. with no overhead whatsoever compared to C-style pointers). It's simply a perfectly-safe memory optimization (the language leaves the runtime representation of enums (of which Option is one) deliberately unspecified so that these types of optimizations can be made). It doesn't make Rust any less safe, as the language itself still has no notion of null pointers.
- drivebyacct2 13y agoCan you give a syntax sample? While your text makes sense, it's not translating into a functional difference.
- duaneb 13y agoI would guess that the implementation was specialized but the language semantics (including safety from null derefs) would not change.
- pcwalton 13y agoIt's just an implementation optimization. The interface didn't change.
- MichaelGG 13y agoFWIW, F# has a similar option. You can make one case in a discriminated union be represented by null. This is a handy perf optimization as you can check that case by comparing to null (instead of a global singleton or allocated object).