Austral: A systems language with linear types and capabilities
Interesting observation that contradicts my experience:<p>&gt; A common misconception is that checking for allocation failure is pointless, since a program might be terminated by the OS if memory is exhausted, or because platforms that implement memory overcommit (such as Linux) will always return a pointer as though allocation had succeeded, and crash when writing to that pointer. This is a misconception for the following reasons:<p>&gt; Memory overcommit on Linux can be turned off.<p>&gt; Linux is not the only platform.<p>&gt; Memory exhaustion is not the only situation where allocation might fail: if memory is sufficiently fragmented that a chunk of the requested size is not available, allocation will fail.<p>This is kind of the eternal vim vs eMacs debate but for malloc. In practice, I’ve not found this philosophy to be useful and actually problematic and the reasons given are the “easy” ones to convince more junior engineers. They’re true btw and the counter points provided aren’t really convincing. Regardless, the real reasons are:<p>* Memory allocation failures happen infrequently in practice.<p>* No one writes tests that simulate behavior of code under allocation failures.<p>* Memory allocation failures are basically treated as contract violations anyway in terms of triage - it’s not different from any other bug and you’d still need to fix it.<p>Crashing on a memory allocation failure:<p>* there’s no untested error recovery code to worry about<p>* the cause of the malloc failure means something else is broken &#x2F; misconfigured. A crash tells you what to fix &#x2F; when to fix it. A silent recovery attempt (when successful) will mask this and shift the problem (eg bug in error handling later or something)<p>There are times when you allocate memory and <i>could</i> handle failure gracefully by rejecting the request or something. However, as I mentioned. Memory allocation failures are rare and when they happen you need to fix a bug anyway. So crashing on a rare condition instead of running untested error recovery code is probably preferable in general.<p>Context: I have experience in mobile, embedded, desktop, and cloud so I’ve seen the gamut of dev environments. And everywhere the “abandon on malloc failure” turns out to be a more maintainable strategy that results in more robust code that’s simpler and shorter and faster&#x2F;cheaper to develop because you’re not writing and thinking about error handling paths that never get run.<p>Regardless, it is kind of interesting to see a language adopt this philosophy. Maybe that can address some of the problems of trying to do this manually in other languages. I’m skeptical because the error paths problem remains, but I’m open to the experiment