On 17 Jul 2002 at 11:27, Andrew Koenig wrote:
How about a class that represents a file? If you ask it for a single iterator, that's easy. If you ask it for a multiple iterator, it checks whether the file is really an interactive device such as a pipe or a keyboard. If so, it uses a buffering mechanism to simulate multiple iteration; otherwise, it lets the multiple iterators access the file directly.
Then when you ask to iterate over the file, you automatically get the least cumbersome mechanism needed to support the kind of iteration that you requested.
OK, it's a pipe, and one iterator wants to go past what's been received. Is that iterator at EOF? Not really, just "temporary EOF". So should it block? But I'm single threaded and receiving asynchronously. Oh, and it turns out to be a humongous download, and what happens if the buffering mechanism runs out of memory / disk space. Does my process die?
Aargh. Too much magic. Too many corner cases.
-- Gordon http://www.mcmillan-inc.com/