4 ms·
> Well you say "that family" but you only give examples of why Rust isn't Ada. Ada is the language I work with daily, but I think other languages that have bee
by LiamPowell 2y ago
> Well you say "that family" but you only give examples of why Rust isn't Ada.
Ada is the language I work with daily, but I think other languages that have been designed for the ground up for safety have similar features.
Aside from arrays vs slices, the solutions to these problems all seem less ergonomic than they could be if they were a part of the core design of the language, which is my major issue here rather than whether it is possible at all to do such things.
> You can't do it in C (the array types do exist in C, but they decay to pointers at the edge of any function.
You can pass around a pointer to an array in C (int (*)[3]), but I don't think it's worth considering as the language and standard library are not designed to make working with it easy. This is the same as my issues with Rust, if declaring a new type to represent a number of files isn't as easy as just using a u32 then no one will use it, etc..
My opinion is that the absolute safest way to do something needs to also be the easiest way to ensure that users always pick the safest option. Ideally the user would even have to go out of their way to pick the more unsafe option. Rust is really good at this with memory and thread safety, just not as much with the rest of the language (although it's certainly better than C).
As an addendum to my last example in the GP, I suppose the borrow checker prevents any safety issues from such a type requiring a separate allocation without generics that I was originally considering, although it does not help with leaks.
- estebank 2y ago> This is the same as my issues with Rust, if declaring a new type to represent a number of files isn't as easy as just using a u32 then no one will use it, etc.. #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] #[repr(transparent)] pub struct FileCount(pub u32); The annotations aren't needed until you make these part of your API and you want to communicate specific actions, but it's likely close what you'd end up with. The first thing I'd do, and likely get away with, is struct FileCount(u32); > My opinion is that the absolute safest way to do something needs to also be the easiest way to ensure that users always pick the safest option. Agreed.