D - Unsafe and doomed

ilya-stromberg ilya-stromberg-2009 at yandex.ru
Fri Jan 3 23:42:49 PST 2014


On Saturday, 4 January 2014 at 05:16:38 UTC, Walter Bright wrote:
> On 1/3/2014 8:36 PM, Timon Gehr wrote:
>> On 01/04/2014 05:31 AM, Walter Bright wrote:
>>> ...
>>>
>>> Null pointers are not a safety issue.
>>
>> In the general sense of the word, yes they are.
>
> Please explain.

I don't know Timon Gehr's opinion, but it will be very nice to 
have NOT NULL pointers.

NULL pointer means that I don't have any valid object, and it's 
good situation. But there are a lot of situations when function 
must take a valid object (at least NOT NULL pointer). D allows:

1) use `if(p is null)` and than throw exception - it will be 
safe, but I have additional `if` check
2) ues `assert(p !is null)` - theoretically, it will be safe, but 
program can have different situation is realise mode and fails 
(for example, because nobody provide the same example in debug 
mode)
3) do nothing - programmer just forgot to add any checks

Also, I must to add unit tests for every posible case usage of 
that function with a valid object. So, it's kind of dynamic 
typing that can be done by compiler type system.

So, in a few cases null pointers are a safety issue.


More information about the Digitalmars-d mailing list