Hacker News new | past | comments | ask | show | jobs | submit login

That's true in the majority of cases. However, the code could be written as it is for performance reasons. If someObject is a field in the current object, that isn't that bad, especially if it also is an instance of a nested class.

Also, weirdly, that isn't something the language forbids. It doesn't even make it possible for library writers to prevent it.

I still think we will see some language changes before the official release here in this area because naive users will run into too many weird issues with the current behavior.

For example, if the goal is to have normal function arguments immutable, I think it would be more natural to forbid functions from calling mutating methods on their arguments, unless they are specified as inout.

On the other hand, good compiler warnings might be enough for preventing programmers from accidentally copying containers.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: