On 11/6/2010 4:02 PM, Walter Bright wrote: > Jérôme M. Berger wrote: >> I thought D was supposed to be a pragmatic language? All this means >> is that we need a compromise between what would be ideal (being able >> to represent arbitrary conditions and have them statically enforced >> at compile time) and what can be realistically achieved. Your >> argument seems to be: "since there are cases which we won't be able >> to handle, let's not do anything at all, not even the cases which we >> could handle". > > > The idea is to find a way to solve this in the general case, not the > specific case of non-null pointers. Then we've got dynamite in our > hands, rather than warmed over toast.
But it's not a specific case if you look at it from OOP perspective! The problem of restricting types was solved in OOP. Every time you inherit a class, you make it more specific. This allows you to restrict types all you want, and the compiler enforces your restrictions. For example, you can create a class that represents an even number and accepts only even numbers in its constructor (trowing exception otherwise). You can then extend it and create a class that only accepts every second even number, and so on. Since D is a statically typed language, attempts to assign arbitrary class to a variable intended for Even objects is caught at compile time (instead of waiting until someone references a missing method or attribute at run-time). Null is the only wrench in the gears here.