Spec#, nullables and more
Adam Burton
adz21c at gmail.com
Sat Nov 6 11:39:23 PDT 2010
Walter Bright wrote:
> bearophile wrote:
>>> Suppose, for example, you are appending the numbers 1..5 to the array,
>>> and somehow appended a 17. Many moons later, something crashes because
>>> the 17 was out of range.
>>
>> This bug doesn't happen in Ada (and Delphi), because you define a ranged
>> integer type like this: subtype Small is Integer range 1 .. 5;
>
> Since you're the second to misunderstand me in the same way, I obviously
> wasn't very clear at all. Allow me to restate:
>
> Suppose, for example, you are appending prime numbers to the array, and
> somehow appended a 25. Many moons later, something crashes because the 25
> was not prime.
I wouldn't consider that as the same thing. null represents the lack of a
value where as 25 is the wrong value. Based on that argument the application
should fail immediately on accessing the item with 25 (not many moons later)
in the same manner it does nulls, but it doesn't because 25 is the wrong
value where as null is a lack of value.
As with the array allocation example earlier you initialise the array to
nulls to represent the lack of value till your application eventually gets
values to assign to the array (which may still be wrong values). As shown by
my alternative example non-nulls allow you to define that a
variable/parameter wants a value and does not work when it receives nothing.
However in the case of the array because all the information is not there at
the point of creation it is valid for the array items to represent nothing
till you have something to put in them.
More information about the Digitalmars-d
mailing list