3 ms·
No you don’t. You can use the standard linked list that is already included in the standard library. Coming up with these niche examples of things you need uns
by School-Cotton 2y ago
No you don’t. You can use the standard linked list that is already included in the standard library.
Coming up with these niche examples of things you need unsafe for in order to discredit rust’s safety guarantees is just not interesting. What fraction of programmer time is spent writing custom linked lists? Surely way less than 1%. In most of the other 99%, Rust is very helpful.
- vikramkr 2y agoI think the point is that it's funny that the standard library has to use unsafe to implement a data structure that's like the second data structure you learn in an intro to CS class
- Sharlin 2y agoYeah, but Rust just proves the point here that (doubly) linked lists a) are surprisingly nontrivial to get right, b) have almost no practical uses, and c) are only taught because they're conceptually nice and demonstrate pointers and O(1) vs O(n) tradeoffs. Note that safe Rust has no problems with singly-linked lists or in general any directed tree structure.
- School-Cotton 2y agoWhy is it particularly funny? C has to make a syscall to the kernel which ultimately results in a BIOS interrupt to implement printf, which you need for the hello world program on page 1 of K&R. Does that mean that C has no abstraction advantage over directly coding interrupts with asm? Of course not.
- cesarb 2y ago> C has to make a syscall to the kernel which ultimately results in a BIOS interrupt to implement printf, That's not the case since the late 1990s. Other than during early boot, nobody calls into the BIOS to output text, and even then "BIOS interrupt" is not something normally used anymore (EFI uses direct function calls through a function table instead of going through software interrupts). What really happens in the kernel nowadays is direct memory access and direct manipulation of I/O ports and memory mapped registers. That is, all modern operating systems directly manipulate the hardware for text and graphics output, instead of going through the BIOS.
- School-Cotton 2y agoThanks for the information (I mean that genuinely, not sarcastically — I do really find it interesting). But it doesn’t really impact my point.
- tux3 2y agoNo, that's how the feature is supposed to work. You design an abstraction which is unsafe inside, and exposes a safe API to users. That is really how unsafe it meant to be used. Of course the standard library uses unsafe. This is where you want unsafe to be, not in random user code. That's what it was made for.