Re:John Carmack on Mutable Variables
by bathtub365 on Friday October 31, 2025 @01:25AM
(#45768692)
Are there languages that automatically extend this to things like data structure members? One of the things I like about the C++ const keyword is that if you declare an instance of a struct/class as const it extends that to its members. If the instance isn’t const, you can still mutate them (as long as they aren’t declared const within the structure itself)
[ Parent
| on HN ]
Rust works this way, yes. There are escape hatches though, which allow interior mutability.
Yeah, here's an example: https://play.rust-lang.org/?version=stable&mode=debug&editio...
Re:John Carmack on Mutable Variables
by umanwizard on Friday October 31, 2025 @04:23AM
(#45769534)
If I understand what you’re asking correctly, rust is also like this. If you have a non-mut value of (or non-mut reference to) an object, you only get non-mut access to its members.