Hacker News new | ask | show | jobs
by ehsankia 473 days ago
If it's safety/correctness versus performance, I think the default should be the former. Copying, while inefficient is generally more correct and avoids hard-to-debug errors. It's the whole discussion about premature optimization. I'd rather make a copy than make sure the array is not mutated anywhere ever.
3 comments

Yes, everyone agrees with you. The claim you responded to was that you should have to be explicit, because it is very easy to unintentionally copy. For example, it is easy to copy when there is never more than one live pointer to a datastructure. It's easy to copy when you allocate a resource in a function and return it, which makes the original an orphan which is then immediately freed. It's extremely easy to make a mistake which prevents move from working and you have to go back and carefully check if you want to be sure. It should be trivial to just say "move this" and if something isn't right it's an error at compile time, rather than just falling back to silently being wasteful.
This exact problem is basically why Rust exists.
I'm not saying it should silently alias any more than it should silently copy. It should give an error, and require the developer to explicitly copy or explicitly alias.