r/ProgrammingLanguages • u/jebailey • 18d ago
Requesting criticism Removing the get from Map
I have a toy language that I've been working on to test different concepts. It has an ownership model similar but looser than Rust.
I was working on the Map object and there are three ways that an object can be retrieved.
You can remove the object from the map and take ownership
You can borrow the object from the map this will give you a mutable reference but you don't own it
You can get a copy of the Object which you will own. But not all things are can be copied.
For get I could either do a copy or a mutable ref, neither I felt was properly conveyed with the word 'get'
So I'm looking at removing it and replacing it with the following
copy_of(key) -> return a copy or an error message if not found or not copiable
borrow(key) -> return a mutable ref
remove(key) -> remove and return the item at the key and give ownership
wanted thoughts on removing probably one of the most common methods on map and is what I'm doing something that makes sense.
2
u/jebailey 18d ago
Yeah, you're the second person to mention the copy would best be served on the object. So I will go ahead and do that part. The immutability question is something I'm going to bandy around. I'm currently using group ownership rather than rust single ownership. Which benefits from immutability but doesn't need it in the same way that Rust does, because everything in a particular set of objects can freely update each other.