2 ms·
Move should have been the default…
by aaaaaaaaaaab 4y ago
Move should have been the default…
- p4bl0 4y agoWhat do you mean? Like using a variable automatically sets it as unusable anymore except if you opt-in to mark it as still usable? It kinds of remind me of linear logic, but wouldn't that be a real pain to program with?
- roblabla 4y agoSo, Rust has this very awesome thing where all variables are move by default, but types may opt in to be copied by implementing the Copy trait (a trait being the Rust equivalent of a Swift protocol). This works exceedingly well. It essentially maps to what I want to do in almost all cases: Things that can trivially be copied (because they don't contain a resource) will usually work as you'd expect in any other programming language, while things that cannot (because they contain a resource like a file descriptor, or an owned pointer to some allocated memory) will indeed mark the old variable as unusable. This is a really pleasant model to work with. So much so that I miss it terribly whenever I work in another language.
- thealistra 4y agoI believe this was in the swift roadmap to have an opt-in borrow semantics for a block of code, if you want to do low level systems programming - just like rust. But I guess it didn't fit to migrate from current obj-c ecosystem so they left it for later.
- dagmx 4y agoSwift is ref counted so I’m not sure how having move semantics be the default would really work with that? If it weren’t, I’d agree, but that was one of the core tenets of the language as a successor of ObjC