[:] as empty associative array literal, plus warning for null

Regan Heath regan at netmail.co.nz
Fri Jul 5 02:05:32 PDT 2013

On Thu, 04 Jul 2013 18:26:09 +0100, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:
> Why do you want so much an empty array that's not null? I can't make  
> sense of this entire argument.

Suppose you have a web page, suppose it has a text field on it called  
"comment".  Suppose you load a pre-existing record from your database and  
populate the page, suppose it had a value for comment, suppose you want to  
set that comment to be blank.  you edit and click save.

The code backing this page is going to get a string for "comment", that  
string should be empty but not null.

Why?  Because if it were null it would have a different meaning.  It would  
mean that the comment field was not present on the page at all, and should  
not be altered.

There are many such examples.  All of them can be worked around by various  
means but these are all more complex and require additional containers or  
variables to represent state.

null  - does not exist, was not specified.
empty - exists and was intentionally set to be empty.

I think arrays will be most useful if we can treat them like safe  
reference types - this wrappers around the unsafe ptr reference type.  To  
do that, we need null/empty to be stable/reliable states.

If not, then array becomes like 'int' and we have to invent a special  
value to represent the null case (or use other containers/variables to  
represent null) like we do for int.


Using Opera's revolutionary email client: http://www.opera.com/mail/

More information about the Digitalmars-d mailing list