3 ms·
So what's up with Rust then? Sorry for noob questions but is it: 1) Ownership model means RC only needs to be used rarely in Rust, and ARC even less, minimiz
by jbooth 9y ago
So what's up with Rust then? Sorry for noob questions but is it:
1) Ownership model means RC only needs to be used rarely in Rust, and ARC even less, minimizing the throughput impact?
2) Simplicity benefits were overwhelming considering the targets you were aiming for?
Or something else?
- continuational 9y agoRust adds a lot of cognitive overhead for the ownership and borrowing model. Most languages are not designed like that, because productivity takes precedence.
- unscaled 9y agoMuch of the world is still using C and C++, where every piece of memory has ownership and lifetime. Yes, they don't enforce you to properly specify and transfer ownership semantics at compile time with the borrow checker (although you can enforce some of these things with modern C++), but the cognitive overhead is there. And if you make a mistake you don't get a scary compiler error - you just get a hard to find memory leak, an even harder to find data race or a gaping security hole. Even Go (which usually touted as the perfect alternative to Rust in these conversation), has a lot of cognitive overhead related to ownership. Every time you take a byte slice and pass that forward to another function, you have to know whether that function appends to that slice, in which case your original slice will get overwritten. Case in point: arr := []byte("Hello World") b1 := arr[:6] b2 := append(b1, 'Z') fmt.Println(string(b2)) fmt.Println(string(arr)) https://play.golang.org/p/QIN5SAIL5M https://play.golang.org/p/QIN5SAIL5M Many byte manipulation functions in the go std library and ecosystem have append semantics, for instance: https://godoc.org/regexp#Regexp.Expand https://godoc.org/regexp#Regexp.Expand Better yet, Go often makes it very hard to notice whether you're copying values or just assigning a reference. On the other hand, some languages like Java don't even let you copy values reliably without special support in the class and in the same time highly encourage doing everything with stateful mutable objects. You can't just go and pass all these neat POJOs and beans around to functions modifying their state if they get used around somewhere else, right? This is exactly what all these rust borrow checker warning are all about! The only language I can think of which is completely devoid of ownership semantics overhead is Haskell. Everything is immutable, look ma no side effects! So if this is really the only benchmark for productivity, Haskell is the most productive language ever.