OutputRange should be infinite?

Steven Schveighoffer schveiguy at yahoo.com
Tue Oct 9 11:28:26 PDT 2012


On Tue, 09 Oct 2012 14:18:30 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 10/9/12 11:52 AM, monarch_dodra wrote:
>> On Tuesday, 9 October 2012 at 15:27:44 UTC, Steven Schveighoffer wrote:
>>> On Tue, 09 Oct 2012 09:39:32 -0400, monarch_dodra
>>> <monarchdodra at gmail.com> wrote:
>>>
>>>> On Tuesday, 9 October 2012 at 13:22:28 UTC, Steven Schveighoffer  
>>>> wrote:
>>>>> [SNIP]
>>>>
>>>> I tend to disagree with your examples, because, you are mixing the
>>>> notion of run-time failure with logic error.
>>>
>>> They are one and the same.
>>>
>>> Putting into a file that runs out of disk space, and putting into an
>>> array that runs out of memory.
>>
>> I'm not convinced.
>>
>> A file running out of memory is an implementation defined limitation
>> that is out of the field of control of the developer, just as much as an
>> OutOfMemoryError.
>>
>> An array that runs out of memory is predictable logic error. The problem
>> is that we aren't giving the developer the tools required to predict it.
>
> I agree with this distinction. In brief a disk getting full is an  
> exceptional occurrence whereas a non-appendable structure running out of  
> room is a different category of error.

I also agree that running out of disk space or general heap memory is a  
different high-level error.

But it depends on the level you are looking from.

 From the low level, it's "I've been asked to put A into B, and B is saying  
no".  From that point of view, it doesn't seem any different to me, and I  
don't know that 'put' really is the one to decide that.  Each range itself  
must decide whether this is absolutely a logic error or a runtime error.

Two different things to think about:
   1) you can check how much disk space is left just like you can check how  
much space is left in your array.
   2) The determination of how much space is available in a range could be  
unavailable at runtime, even for memory-based ranges.

I agree that if you try to copy an input range into a smaller *array*, we  
should handle that as a logic error.  But as a range in general, I don't  
think it can be handled without a runtime error.  In other words, the  
range should decide what kind of error it is, not the definition of  
OutputRange.

-Steve


More information about the Digitalmars-d mailing list