(non)nullable types

Michel Fortin michel.fortin at michelf.com
Mon Feb 9 03:25:43 PST 2009


On 2009-02-08 23:19:55 -0500, Brian <digitalmars at brianguertin.com> said:

> On Mon, 09 Feb 2009 04:25:55 +0300, Denis Koroskin wrote:
> 
>> So, let's ask the community: Would you like to see nullable types in D?
>> 
>> http://www.micropoll.com/akira/mpview/539369-138652 (please, don't abuse
>> by voting multiple time)
>> 
>> Explain your reasoning in newsgroups. Thank you.
> 
> i vote yes, i would absolutely love non-nullable types. in some cases i
> even use dummy objects to avoid null checks.

Same here.

A non-nullable pointer, when used as a function argument, is a contract 
the compiler can enforce at the call site. If 80% of your functions 
accept only non-nullable pointers, then it means you can remove about 
80% of your checks for null without worries of seeing your program 
crash.

For global and member variables, non-nullable pointers means you can 
get an error exactly where the infringing code first put a null where 
there shouldn't be one; not later when someone tries to access it.

And I think non-nullable should be the default because it's safer and 
it'd force people to be explicit when they want to take the 
responsability to work with nullable ones.

So it's a yes.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list