logoalt Hacker News

VorpalWayyesterday at 11:46 AM4 repliesview on HN

Yes that is annoying, but I don't know of any mainstream systems language that does. C and C++ can also have allocations anywhere, and C++ have exceptions. And those are really the only competitors to Rust for what I do (hard realtime embedded).

Zig might be an option in the future, and it does give more control over allocations. I don't know what the exception story is there, and it isn't memory safe and doesn't have RAII so I'm not that interested myself at this point.

I guess Ada could be an option too, but I don't know nearly enough about it to say much.


Replies

jibalyesterday at 12:11 PM

Zig doesn't have exceptions, it has error unions, so basically functions return either a value or an error code and the caller is forced by the language to note which was returned. And instead of RAII it has defer ... which of course can easily be forgotten or mis-scoped, so it's not safe.

gethlyyesterday at 12:33 PM

For allocation, Zig and Odin. Zig is explicit and Odin is implicit.

show 2 replies
alfiedotwtfyesterday at 11:43 PM

Tbh I’ve found that whenever I’ve hit MAX RAM, failed allocations are not the biggest problem you should be focusing at that time.

Sure, it would be nice to get an error, but usually the biggest threat to your system as a whole is the unapologetic OOM Killer

show 1 reply
FpUseryesterday at 5:33 PM

>"Yes that is annoying, but I don't know of any mainstream systems language that does. C and C++ can also have allocations anywhere, and C++ have exceptions."

C++ has a way to tell to compiler that the function would raise no exceptions. Obviously it is not a guarantee that at runtime exception will not happen. In that case the program would just terminate. So it is up to a programmer to turn on some brain activity to decide should they mark function as one or not.