Spec#, nullables and more

Simen kjaeraas simen.kjaras at gmail.com
Sat Nov 6 16:21:22 PDT 2010


Gary Whatmore <no at spam.sp> wrote:

> non-nulls don't solve basic problems like arrays, basic collections in
> the library (custom fill policy).

As I've posted elsewhere, arrays (and other collections) will have to
work slightly differently for non-nullable elements:

1 .length is read-only (or read/decrease only)
2 Length can be increased by concatenation only
3 Can only be created with a nonzero length with a runtime check of a
   nullable-element array/collection, or as a literal containing only
   non-nullable elements.

And yes, there may be cases where this is not good enough, and you need
to have nullable elements. That does not mean non-nullable types are
borked by default, you just use nullable elements, and accept that you
have to work harder to prevent segfaults. In many cases, rule #3 will
allow you to create your collection using nullable elements, and casting
it to non-nullable afterwards.


> Can't force me to read. I've made my choice of using D already. Nothing  
> will change that.

He's not trying to make you change language, but to inform you of how
other languages have solved the problem.

-- 
Simen


More information about the Digitalmars-d mailing list