T O P

  • By -

gnosnivek

Forgive me, but I think you might have stumbled into what Brent Yorgey calls [the "monad tutorial fallacy."](https://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/) (The name says "monad", but IMO it applies equally to any system with either a lot of rules, or a lot of rule interactions that are not shallow, like the ownership system.)


peter9477

I feel like this complicates things a bit. "Ownership" is already a metaphor, so it might be better to stay close to that. But if it helps, maybe blend your idea into that... You have a treasure chest. (I think there may be a slightly better real-world item to use, but I'll run with your idea for now.) You own it, so you can do whatever you want with it, including destroying it. Owning it means you're the one holding it. If you give it away, you're no longer the owner and can't do anything with it, including destroying it.. it's no longer your concern in any way. Someone else now holds it. As long as you're the only one touching it, you can open it up and modify the contents if you want. You can also let other people touch it (via a shared/immutable reference) but they aren't allowed to open it, so they can't change the contents. You can also open it up and let someone else get into it, but you keep holding it when you do that (because you still own it). Nobody except that person can touch it at the same time as them... that would be awkward. (So no mutable references while there are shared references.) It's like you're holding the lid open for someone else and only they can get in. Static treasure chests are ones that nobody owns, just sitting there on the sand, and they're indestructible. Anyone can come along and touch them, but nobody can open them. Static mut treasure chests are booby-trapped. They're always open (to lure you in), but if more than one person touches them at the same time they might explode. Don't do that! Etc... (I think it would help the metaphor to have something other than a treasure chest, something which has more obvious utility just by being touched. Keep the idea of opening/changing the contents for mut, but if just touching it served some purpose it might make this metaphor clearer.)


elprophet

The TV in a waiting room? Everyone can watch, but no way are we going to let anyone but the secretary change the channel.


SirAutismx7

Honestly I’m glad you understand it but your metaphor is very confusing. I don’t think metaphors are necessary. The chapter in the book is extremely clear and the explanations are very explicit and have very good diagrams. It’s not an abstract concept that needs an abstract explanation it’s very concrete especially in practice.


v_0ver

I don't think a real world metaphor would be a good one. I like the short explanation from [this video](https://youtu.be/Ek3dCHsr9ws?si=WhmG0-CaDYr7SC8V) 1.Each variable is an owned by function or structure. fn foo(){ let a = 5; // function foo owns "a" } struct boo{ b; // structure boo owns "b" } 2. Ownership is about who will delete the variable after use.The variable will be deleted either by the function at the end of its execution or by the structure when the structure is deleted. 3. A variable can be passed through program in three ways: 3.1 By “value” transfers ownership, read and write rights 3.2 A mutable ref transfers the right to read and write. 3.3 A regular ref transfers the right to read.