3 ms·
> people end up passing id's around everywhere instead of references Well, a reference (or a pointer) is just an index into a giant global and mutable array of
by db48x 5y ago
> people end up passing id's around everywhere instead of references
Well, a reference (or a pointer) is just an index into a giant global and mutable array of bytes, which is pretty crazy!
Passing around indexes into specific arrays of objects is a lot less crazy. The indices are stable even when you reallocate the array, for example. Think of them as offsets, rather than pointers.
- skohan 5y agoYeah for me it's more around the ergonomics (and imprecision) about using indexes. It's a perfectly workable approach, but passing around offsets feels like I'm breaking the contract a bit. The compiler doesn't know which index goes with which data structure, I'm just asking the compiler to trust me that I'm pairing them correctly. Also it tends to be more boilerplate than just having a direct pointer stored inside the data structure. Don't get me wrong, I understand all the problems with pointers, but it the UX is better in a lot of cases.
- db48x 5y agoIndices don’t need to be imprecise. In Rust at least you can give different types for different indices, so that you cannot mix them up.