3 ms·
I suspect that a lot of the inconvenience of modelling non-linear problems in Rust actually doesn’t come down to ownership semantics alone, but the combination
by chrismorgan 6y ago
I suspect that a lot of the inconvenience of modelling non-linear problems in Rust actually doesn’t come down to ownership semantics alone, but the combination of ownership semantics and the low-level memory model. However, I don’t have any solid evidence to support this, because ownership semantics have only really been implemented with the low-level memory model, because the low-level memory model strongly benefits from it (memory safety; it more closely matches how computers work internally at that low level) and GC languages don’t need ownership semantics, and people don’t generally restrict things without cause (and ownership semantics are definitely a restriction).
My thesis here is that Rc<RefCell<_>> and similar are an effective escape hatch to ownership semantics, but they’re much less convenient than a garbage-collected type in a scripting language specifically because of the language’s low-level memory model. A GC language with ownership semantics might be able to obviate RefCell, which is the cause of Rc<RefCell<_>>’s inconvenience.
I’d be interested to see experimentation with ownership semantics in languages with higher-level memory models (which broadly means GC languages). My thesis could turn out to be quite wrong, and I haven’t worked out all the details of how the combination would work (especially I’m hazy on parts of removing RefCell, which is pretty critical), but I think it could be worth some research—ownership semantics for its own sake, rather than ownership semantics for memory safety.
> 10. Getting used bypassing the borrow checker to reduce fighting implies people have just found a way to cope with the constraints it imposes.
Here’s the thing, though: it’s not just about finding a way to cope with the constraints it imposes; it’s also about thriving within the constraints it imposes, because it stops you from doing problematic things and guides you in the path of better designs much of the time (though non-linearity can definitely be a problem; it’s not all buttercups and daisies). When I work in JavaScript, I spend half the time missing ownership semantics, occasionally feeling downright miserable because ownership semantics would have made a problem far easier or less dangerous. Remember what I said about ownership semantics for its own sake rather than ownership semantics for memory safety? Yeah, most of the time I love Rust’s ownership semantics for the modelling rather than the memory safety.
- KenoFischer 6y agoYes, I think you're onto something. Essentially what if we modeled linearity like in Rust, but then did GC over the maximally linear data graph we can find. I've been wanting to play with some ideas in this direction, but haven't had the time.
- fpoling 6y agoAt the machine level there is no ownership. A computer has fixed amount of RAM and CPU can change an arbitrary word at any time. Ownership is an attempt to partition that with the goal of simplifying things and say that particular area of memory can only be modified/accessed at particular time by particular code. Isolated memory between processes does that at OS level, Rust and OOP try it inside a particular process, but they do it in a different way.
- chrismorgan 6y agoI wondered if anyone would call me out on that, when I first wrote it! I agree: at the most fundamental level data types aren’t real; even pointers don’t exist, they’re just a convention. What I was trying to get at is that at the fundamental level everything’s a value; when comparing high-level and low-level memory models, the key difference is whether everything’s a value or a reference (though many high-level models still support some kind of value types). When you have value types, ownership is real, and reflects how the machine works. Because the real world of CPUs isn’t quite that theoretical fundamental level: there are instructions for dealing with pointers; the concept of the stack is built in; things like that. If you have a stack variable, it’s inherently owned by the one place (though whether the language freely permits mutation from multiple places is another matter). So yeah, in the end I maintain my position that ownership semantics more closely match how computers work at that low level.
- baetheus 6y agoI agree! At the most fundamental level (that I know of) all bits are two ranges of voltage, light, or magnetism in a system (although I am aware of deeper understandings based in physics). We have decided to give the meanings of 0 and 1 to those ranges. We have also given meaning to collections of bits by calling them pointers or ints. We have given meaning to other collections of bits by encoding various symbols in them and a logic based on those symbols. My point here isn't to be pedantic but to argue this point: The fundamental quality of computing is that it abstracts a physical system to a logical one. In this light the realness of a data type is the same realness of a bit, since they are both structures that give way to a more defined logical system, one built on the next. To speak to the OP's claim of a category mistake I think he misses this valuable insight. The "realness" of programming objects and the semantics of moving them and copying them is the same "realness" of the bit or the data type. This is to say that the category that programming objects are contained within is, for lack of a better phrase, "the category of logical abstractions built on physical systems". The reuse of "move" and "copy" to represent similar processes to those we use with physical systems is a "logical encoding", not an error. In fact, the op makes the categorical mistake by saying that we mean "physically move" when we mean "logically move". That said, this was an interesting read in spite of my disagreements with some assertions.
- dan00 6y ago> I’d be interested to see experimentation with ownership semantics in languages with higher-level memory models (which broadly means GC languages). Haskell might give a few hints how well this works. [1] > Here’s the thing, though: it’s not just about finding a way to cope with the constraints it imposes; it’s also about thriving within the constraints it imposes, because it stops you from doing problematic things and guides you in the path of better designs much of the time (though non-linearity can definitely be a problem; it’s not all buttercups and daisies). Oh yes, and how nice it is to have these constraints verified by the compiler. Perhaps it's this kind of assumption, that less constraints give you more power, without realizing that also the responsibility increases, and at a certain point the complexity overburdens the human mind. Different software domains need different constraints, so the question might be where the sweet spot between languages with different constraints and a language with programmable constraints (aka dependent types) lies. [1] https://www.tweag.io/blog/2020-06-19-linear-types-merged/ https://www.tweag.io/blog/2020-06-19-linear-types-merged/
- gingerBill 6y ago> it’s not just about finding a way to cope with the constraints it imposes; it’s also about thriving within the constraints it imposes This is an extremely important point! Most people try to make a language act like another language, rather than try and embrace how it does things. "When in Rome(, do as the Romans do)" It's like when people try and make C into another language by abusing the macro system, you get a horrible mess compared to if you embraced what the language likes to do normally. Personally, I think Rust's memory model is quite high level, and coupled with its ownership semantics, I cannot do many things such as custom allocators. (Not a singular custom global allocator)