Skip to content

Comment on Swift: Not quite there, but too far gone tooparent

Comments

"Immutability has a slightly different meaning for arrays, however. You are still not allowed to perform any action that has the potential to change the size of an immutable array, but you are allowed to set a new value for an existing index in the array. This enables Swift’s Array type to provide optimal performance for array operations when the size of an array is fixed."

https://developer.apple.com/library/prerelease/ios/documenta...

So immutability is a code safety feature, except in the case of arrays, where it's a performance optimization. That seems counterintuitive.

Thanks. I think it sounds like a bad decision, it can be compile time checked so won't cause performance issues. I wonder what the cost is in the mutable case for the fact that the length can vary.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.