Get the latest tech news
Rust's Ugly Syntax (2023)
People complain about Rust syntax. I think that most of the time when people think they have an issue with Rust's syntax, they actually object to Rust's semantics. In this slightly whimsical post, I'll try to disentangle the two.
The next noisy element is the<P: AsRef<Path>> constraint.It is needed because Rust loves exposing physical layout of bytes in memory as an interface, specifically for cases where that brings performance.In particular, the meaning of Path is not that it is some abstract representation of a file path, but that it is just literally a bunch of contiguous bytes in memory.So we need AsRef to make this work with any abstraction which is capable of representing such a slice of bytes.But if we don’t care about performance, we can require that all interfaces are fairly abstract and mediated via virtual function calls, rather than direct memory access.Then we won’t need AsRef at all: Technically, we are still carrying ownership and borrowing system with us, but, without direct control over memory layout of types, it no longer brings massive performance benefits.It still helps to avoid GC, prevent iterator invalidation, and statically check that non-thread-safe code isn’t actually used across threads.Still, we can easily get rid of those &-pretzels if we just switch to GC.We don’t even need to worry about concurrency much — as our objects are separately allocated and always behind a pointer, we can hand-wave data races away by noticing that operations with pointer-sized things are atomic on x86 anyway. to highlight any specific expression that might fail.It would be much simpler to not think about error handling at all, and let some top-level try { } catch (...) { /* intentionally empty */ } handler deal with it:
Or read this on Hacker News