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

codephantom me at noyb.com
Thu Nov 23 06:32:30 UTC 2017


On Wednesday, 22 November 2017 at 00:39:21 UTC, codephantom wrote:
> On Wednesday, 22 November 2017 at 00:19:51 UTC, codephantom 
> wrote:
>> Its seems to be, that you prefer to rely on the type system, 
>> during compilation, for safety. This is very unwise.
>>
>
> To demonstrate my point, using code from a 'safe' language (C#):
> (i.e. should this compile?)
>
> // --------------------------------------------------
>
> using System;
>
> public class Program
> {
>
>
>     public static int Main()
>     {
>         Foo();
>         return 0;
>     }
>
>     static void Foo()
>     {
>         const object x = null;
>
>         //if (x != null)
>         //{
>             Console.WriteLine(x.GetHashCode());
>         //}
>     }
>
> }
>
> // --------------------------------------------------


Here is another demonstation of why you can trust your compiler:

using code from a 'safe' language (C#):
(i.e. should this compile?)


// -------------------------------------

using System;
using System.IO;

public class Program
{
     public static int Main()
     {
         Console.WriteLine( divInt(Int32.MinValue,-1) );
         return 0;
     }

     static int divInt (int a, int b)
     {
         int ret = 0;

         //if ( (b != 0) && (!((a == Int32.MinValue) && (b == 
-1))) )
         //{
             ret = a / b;
         //}
         //else
         //{
         //   throw new InvalidOperationException("Sorry.. no can 
do!");
         //}

         return ret;
     }

}


// -------------------------------------------------------



More information about the Digitalmars-d mailing list