On 19 May 2016, at 17:38, Jens Alfke <j...@mooseyard.com> wrote:

> I believe Mac/iOS developers usually transfer the entire file because that’s 
> the particular hammer that Foundation provides.

I disagree.  One-shot file system APIs make sense for a lot of reasons:

* It’s generally easier to use.  Consider NSXMLDocument vs NSXMLParser (-:

* It composes well.  Consider the NSXMLDocument example again.  This high-level 
one-shot API is layered on top of a low-level one-shot API.  Which isn’t to say 
that you can’t build streaming APIs on top of other streaming APIs, but it’s 
not exactly easy, and you end up having to build the one-shot ‘convenience’ API 
anyway.

* It’s atomic on write; other folks looking at the file system never see ‘half’ 
the file.

* It radically reduces the state space of the API.  When you read a file with a 
one-shot API, you only have to deal with one possible error.  When you stream 
through a file, you can get an error at any point.

One of the nice things about the file system is that it has reasonable 
performance and error characteristics such that you /can/ deal with it 
synchronously.  Revel in that fact!

I generally find myself streaming through a file only when I’m dealing with 
some sort of I/O pipeline, which is the exception rather than the rule.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware


_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to