let x = ref(...)
is bad and the .contents
syntax is horrendous. it’s confusing and makes no sense to someone who doesn’t understand the internals of how js deals with references and in-memory storage mutability. worse off, it actually exposes this implementation detail.
why is it called ref? because it’s a reference, but that only makes sense if you understand the js implementation, i.e., ref sort of implies mutability in js (for non-frozen objects). why isn’t it let x = mut(...)
or even mut x = ...
?
also, using .contents
is terribly ugly. why is it called contents of what? the ref? but i only want a mutable value.
i can live with let x = ref(...)
but just as we have :=
for ref assignment (which should be changed too, tbh), we should have something for reading the contents, for example ^
:
let x = ref(None)
// or: let x = mut(None)
// or: mut let x = None
x := Some(42)
// or to unify set and get: x^ = Some(42)
let y = x // binds to point to the same ref
let z = x^ // binds to the value contained in the ref
give me your thoughts on this, maybe you have better ideas, i just feel refs are a wart in the language right now.