4 ms·
I've been programming in rust for three years, until I picked up zig recently. I was also worried about memory safety when I started using it, but I've been ple
by smj-edison 1y ago
I've been programming in rust for three years, until I picked up zig recently. I was also worried about memory safety when I started using it, but I've been pleasantly surprised how many safety features it has (it's certainly been easier to debug than the C code I've had to work with). Slices are often mentioned for safety, which they are great, but even better has been all of the casting functions. In Debug and ReleaseSafe mode, @intCast will panic if you try to narrow on integer that's too big. @alignCast checks that the alignment is correct. @bitCast ensures that both types have the same bit width. Non-packed unions will panic if you access the wrong field. Integer under and overflow has revealed some of my bad code like four times now. defer/errdefer is much easier to reason about that "goto cleanup" (it also lets me write custom cleanup code, instead of being beholden to the author's drop implementation).
So no, it's not as safe as rust in terms of memory, but it's quite close, and in the process lets you do some really cool stuff.
- pjmlp 1y agoYou could have achieved the same with Modula-2, which is the mapping to 1978 from those dates.
- smj-edison 1y agoThat's fair. I was born twenty years after Modula-2 was released, so I definitely have gaps in my language knowledge :D
- pjmlp 1y agoPlenty of material over here, https://www.modula2.org/index.php https://www.modula2.org/index.php As for the other ones I listed, https://en.wikipedia.org/wiki/Mesa_(programming_language) https://en.wikipedia.org/wiki/Mesa_(programming_language) (some PDFs linked from there) https://bitsavers.org/pdf/borland/turbo_pascal https://bitsavers.org/pdf/borland/turbo_pascal https://www.freepascal.org https://www.freepascal.org https://docwiki.embarcadero.com/RADStudio/Sydney/en/Delphi_Developer%27s_Guide https://docwiki.embarcadero.com/RADStudio/Sydney/en/Delphi_D... and https://learn.adacore.com/index.html https://learn.adacore.com/index.html http://www.ada-auth.org/arm.html http://www.ada-auth.org/arm.html
- smj-edison 1y agoThanks!