[Grace-core] "Classical" Inheritance for Grace

Andrew P. Black black at cs.pdx.edu
Tue Apr 2 17:29:16 PDT 2013


On 2 Apr 2013, at 15:34 , James Noble wrote:

>> If we agree on that, then self in the initialization expressions is still not an object.
>> So, *may be* should simply not be visible.
>>> Our semanatics are at least safe, if permitting dynamic errors.
>> Our semantic require "multiple levels of contracts" for each different possible initialization status.
> 
> the problem isn't that simple. We can define the problem away -
> and programmers will then just have to code things up with option types.
> (make their own nulls).  This has to be about engineering tradeoffs.

The engineering tradeoffs are about encouraging programmers to be explicit about the object invariants.

I recently (as part of an in class coding session) created an "efficeintDictionary" that had a size field and four fields key1, value1, key2 and value2, as well as a fullDicitonary.   The idea was that it stored dictionaries of zero, one and two elements directly, but bigger dictionaries overflowed into the fullDictionary.  (It turned out not to be very efficient, but thats another story).  The invariant was something like

	self.size = if (size ≠ nil) then size else fullDictionary.size

	size \in {nil, 0, 1, 2}

	(size = 1)  => self.at(key1) = value1

	(size = 2)  => (self.at(key1) = value1) && (self.at(key2) = value2)

	size = nil XOR fullDicitonary = nil

And yes, the code had to do stuff conditional on whether size was nil or not.    Sometimes one has to do stuff like that.

	Andrew



More information about the Grace-core mailing list