Why does nobody seem to think that `null` is a serious problem in D?

Kagamin spam at here.lot
Wed Nov 21 14:21:44 UTC 2018


On Wednesday, 21 November 2018 at 11:53:14 UTC, Alex wrote:
> Am I misled, or isn't this impossible by design?
>
> ´´´
> import std.stdio;
> import std.random;
>
> class C
> {
> 	size_t dummy;
> 	final void baz()
> 	{
> 		if(this is null)
> 		{
> 			writeln(42);
> 		}
> 		else
> 		{
> 			writeln(dummy);
> 		}
> 	}
> }
> void main()
> {
> 	C c;
> 	c.foo;
> }
>
> void foo(ref C c)
> {
> 	if(uniform01 < 0.5)
> 	{
> 		c = new C();
> 		c.dummy = unpredictableSeed;
> 	}
> 	c.baz;
> }
> ´´´

A value passed to ref parameter is assumed to be initialized. C# 
would reject to call function foo.


More information about the Digitalmars-d-learn mailing list