I find Nim less safe than Rust because its unsafe features aren’t segregated in 
any way. Both languages have unsafe features, and those are necessary to 
interface with C or to implement low level functionality. But Rust has the 
brilliant “unsafe” keyword — unsafe language features and C APIs can only be 
used inside a block tagged with “unsafe”, and a function whose behavior is 
unsafe can be tagged “unsafe” so it can only be used in an unsafe block.

What this does is make it very clear what is safe and what isn’t. That’s a big 
help with code and security reviews, lets you make better decisions about what 
3rd party libraries to use, and can help you avoid accidentally compromising 
safety of existing code when modifying it.

I wonder how hard this would be to add to Nim? At a first glance, unsafety 
seems like an attribute that could be tracked at the function level by Nim's 
existing effects system. But the compiler would need to know to add this effect 
when any unsafe language construct is used.

Reply via email to