Michel Fortin wrote:
On 2009-09-26 22:07:00 -0400, Walter Bright <newshou...@digitalmars.com> said:

[...] The facilities in D enable one to construct a non-nullable type, and they are appropriate for many designs. I just don't see them as a replacement for *all* reference types.

As far as I understand this thread, no one here is arguing that non-nullable references/pointers should replace *all* reference/pointer types. The argument made is that non-nullable should be the default and nullable can be specified explicitly any time you need it.

So if you need a reference you use "Object" as the type, and if you want that reference to be nullable you write "Object?". The static analysis can then assert that your code properly check for null prior dereferencing a nullable type and issues a compilation error if not.

I dislike these forced checks.

Let's say you're dealing with a compiler frontend. You have a semantic node that just went through some semantic pass and is guaranteed, by flow control and contracts, to have a certain property initialized that was not initialized prior to that point.

The programmer knows the value isn't null. The compiler shouldn't force checks. At most, it should have automated checks that disappear with -release.

Also, it introduces more nesting.

Also, unless the compiler's flow analysis is great, it's a nuisance -- you can see that the error is bogus and have to insert extra checks.

It should be fine to provide a requireNotNull template and leave it at that.

Reply via email to