News for hackers. Stuff that matters.
Re:Swift arrays are too swift for our own good by Someone on Monday June 09, 2014 @11:14AM (#7868815)
The problem I have with Swift is that Apple minimized the set of containers. There are only two: Dictionary and Array.

Array when mutable acts like a list: items are indexed by an integer, and you can replace, add, and remove items.

Array, when immutable acts like an area of contiguous memory: items are indexed by an integer, and you can replace items.

Dictionary, when mutable, acts like a map: items are indeed by key, and you can replace, add, and remove items.

Dictionary, when immutable, acts like a read-only map: items are indexed by key. You cannot add, remove or even replace items.

That is inconsistent. I think they would be better of adding List as a third container type, and changing Array to a fixed size (at creation time) container. Immutable Lists and immutable Arrays would behave exactly the same, but I don't see that as a problem.

On top of that, they chose to make Arrays and Lists value types, (prematurely?) optimized Arrays (but not Dictionaries) to copy-on-write their data, and decided to make that manual copy-on-write (to ensure that an Array is yours and only yours, you have to call unshare on it)

My disclaimer is that I only read the ePub that Apple provided, and somewhat partly so.

There are no comments on this comment yet.