References in D

Franciszek Czekała" <home at valentimex.com> Franciszek Czekała" <home at valentimex.com>
Wed Oct 3 02:41:59 PDT 2012


On Wednesday, 3 October 2012 at 08:11:32 UTC, Franciszek Czekała 
wrote:
> On Saturday, 15 September 2012 at 17:12:23 UTC, Jonathan M 
> Davis wrote:
>> On Saturday, September 15, 2012 15:24:27 Henning Pohl wrote:
>>> On Saturday, 15 September 2012 at 12:49:23 UTC, Russel Winder
>>> 
>>> wrote:
>>> > On Sat, 2012-09-15 at 14:44 +0200, Alex Rønne Petersen 
>>> > wrote:
>>> > […]
>>> > 
>>> >> Anyway, it's too late to change it now.
>>> > 
>>> > I disagree. There are always opportunities to make changes 
>>> > to
>>> > things,
>>> > you just have manage things carefully.
>>> 
>>> I don't know if people really use the ability of references 
>>> being
>>> null. If so, large amounts of code will be broken.
>>
>> Of course people use it. Having nullable types is _highly_ 
>> useful. It would
>> suck if references were non-nullable. That would be _horrible_ 
>> IMHO. Having a
>> means to have non-nullable references for cases where that 
>> makes sense isn't
>> necessarily a bad thing, but null is a very useful construct, 
>> and I'd _hate_
>> to see normal class references be non-nullable.
>>
>> - Jonathan M Davis
>
> Agreed. Nullable types are a feature not a bug. There is no 
> need to change it. Bugs occur when you do not know the language 
> rules and make assumptions instead. This can happen whith any 
> language and any rules. As to an example use of nullable 
> references: consider a board game (for example chess). The 
> boards has cells which can be empty or occupied. Model this 
> with an array of class objects  representing pieces. null 
> reference means a cell is not occupied. If you want to remove a 
> piece from the board assign null to it and GC will take care of 
> the rest. Now, doing this with full objects representing empty 
> cells would require needless work to define such "null" objects 
> and would be wasteful of memory (typically boards are sparsely 
> populated). Now imagine a really big board and every cell 
> holding references to useless objects simulating null 
> references. It would not make sense. Saying that null 
> references are evil is just propaganda. Let's keep D a sane 
> language.

Regarding my example: we could probably do with a single "null" 
object stored in all empty cells, but still this would be an 
unnecessary complication.



More information about the Digitalmars-d mailing list