Null references (oh no, not again!)

Denis Koroskin 2korden at gmail.com
Fri Mar 6 05:08:52 PST 2009


On Thu, 05 Mar 2009 06:54:05 +0300, Walter Bright <newshound1 at digitalmars.com> wrote:

> Ary Borenszweig wrote:
>> Walter Bright escribió:
>>> Ary Borenszweig wrote:
>>>> Walter Bright escribió:
>>>>> Ary Borenszweig wrote:
>>>>>> It's not like that. They don't require you to initialize a variable  
>>>>>> in it's initializer, but just before you read it for the fist time.  
>>>>>> That's very different.
>>>>>
>>>>> The only way to do that 100% reliably is to instrument the running  
>>>>> code.
>>>>
>>>> Java does it on compile time.
>>>
>>> Java is a severely constrained language. Even so, how does it do with  
>>> this:
>>>
>>> Foo f;
>>> if (x < 1) f = new Foo(1);
>>> else if (x >= 1) f = new Foo(2);
>>> f.member();
[snip]
> Here's another lovely case:
>
> Foo f;
> if (x < 1) f = new Foo();
> ... lots of code ...
> if (x < 1) f.member();
>
> The code is quite correct and bug-free, but flow analysis will tell you  
> that f in f.member() is "possibly uninitialized".
>
>

These are examples of spaghetti code that will be discouraged by compiler to use. I believe this will lead to code which is easier to read and maintain.



More information about the Digitalmars-d mailing list