Introducing Nullable Reference Types in C#. Is there hope for D, too?

Timon Gehr timon.gehr at gmx.ch
Wed Nov 22 13:21:05 UTC 2017


On 22.11.2017 01:19, codephantom wrote:
> On Tuesday, 21 November 2017 at 20:02:06 UTC, Timon Gehr wrote:
>>
>> I'm confident that you would be able to use null safe languages 
>> properly if that is what had been available for most of your career.
>>
> 
> You do realise, that all of the issues you mention can just be handled 
> by coding correctly in the first place.
> ...

Yes, just like everyone else, I realize that if correct code is written, 
we end up with correct code, but thanks for pointing it out.

BTW of course you must realize that you can make the compiler brutally 
obsolete by just quickly writing down the most efficient possible 
correct machine code in a hex editor, so I'm not too sure why you 
participate in a discussion on the forums of a compiled language at all.

> If your program calls 'std.math.log' with an argument of '-123.4', then 
> that's probably NOT a bug. It's more likely to be incorrect code.

https://en.wikipedia.org/wiki/Software_bug

> Why not bounds-check the argument before passing it to the function?
> ...

Walter said NaN is underused, not me.

> If you access a field of an invalid instance of an object, that's 
> probably NOT a bug. It's more likely to be incorrect code.

https://en.wikipedia.org/wiki/Software_bug

> Before you 
> access a field of an object, check that the object is valid.
> ...

If I know that it is valid, I might not want to check it.
Then, if, let's say, you come along and read my code, I do not need you 
to point out that I didn't check the field access. If you still do, I 
can now either explain to you why it is unnecessary, which will waste my 
time and does not guarantee that you will buy it, or I can write the 
code in a language that requires me to provide the proof up front, such 
that you will not have to bother me. And even if you still doubt that 
the proof is actually correct, it will not be my problem, but instead 
you'll need to take it to the guy who wrote the compiler. This is one of 
the reasons why Walter does not like non-null types. ;o)

> Its seems to be,

Spelling mistakes can be avoided by just spelling correctly.

> that you prefer to rely on the type system, during 
> compilation, for safety.

No, I ideally want the type system to point out when the code is not 
obviously correct. That does not mean I assume that the code is correct 
when it compiles (given that I'm using a language that does not require 
me to prove absence of all bugs, and even if it did I'd at most assume 
that either the language implementation is incorrect or my code is 
correct, with a certain margin of error due to undetected hardware 
failures).

> This is very unwise.
> ...

Thanks for pointing that out.

> btw. what was the last compiler you wrote?
> 

Embarrassing questions can be avoided by just coming up with the correct 
answer yourself.


More information about the Digitalmars-d mailing list