Null references (oh no, not again!)

Joel C. Salomon joelcsalomon at gmail.com
Wed Mar 4 14:05:45 PST 2009


bearophile wrote:
> Walter Bright:
>> Joel C. Salomon:
>>> To avoid this class of bug, you need a simple way to declare what the
>>> acceptable values for a variable are.
>>
>> Languages have had this capability, but it never caught on. People found 
>> it just too tedious.
> 
> What? We use ranges of integers in Delphi at work today :-)
> I have even proposed something similar for D twice in the past. (But to be precise, I often don't use ranged integral numbers for the purpose discussed here).

I was actually thinking of something more ambitious: being able to
declare object invariants (vs. class invariants) that may not be simple,
e.g., “this variable will always be a valid index (or one-past-the-end)
for that array, even when the array is resized.

Something like,
	char[5] arr;
	int idx invariant() {assert((0 <= idx) && (idx <= arr.len));};
for example.

OK, this syntax is clumsy. But some version of this, perhaps amenable to
some mixins for common scenarios like not nullable, within some range,
valid index to some array, &c., could be useable.

—Joel Salomon



More information about the Digitalmars-d mailing list