r/ProgrammingLanguages • u/matklad • Dec 31 '25
Memory Safety Is ...
https://matklad.github.io/2025/12/30/memory-safety-is.html
37
Upvotes
r/ProgrammingLanguages • u/matklad • Dec 31 '25
View all comments
Show parent comment
1
u/koflerdavid Jan 03 '26 edited Jan 03 '26
Such strong formalisms exist, but they are usually quite unergonomic. In fact so unergonomic that the industry has resigned to reduce the blast radius of violations that are too difficult to detect at compile time and sometimes uses static analysis tools where it is not too inconvenient to do so. Trapping at runtime is accepted as a lesser evil since violating memory safety and type safety can have catastrophic and difficult to investigate side effects. Rust's type system is a good progress since it makes it so much easier to write safe native code.
The situation looks a bit better for functional languages with dependent type systems. Among other things, they specifically allow to encode the length of an array in its type, and indexing is only possible if you provide a proof that the index is within the array's bounds. Doing these things is simpler with immutable data since then one doesn't have to take time into account, since modifying a data structure will invalidate any proof derived previously.