[Grace-core] Summer Plans

Andrew P. Black black at cs.pdx.edu
Tue Jun 19 16:15:08 PDT 2012


On 19 Jun 2012, at 14:19 , Kim Bruce wrote:

> My preferred solution at the moment would be:
> 
> 	class aRectangle.at (center: Location) width (w:Number) height (h:Number) -> ShapeType {
> 		def topLeft
> 	        def bottomRight
> 		method setUp {       // confidential  -- perhaps put at the end of the class def
>   			def diagonal = w at h
> 			def semiDiagonal = diagonal / 2
> 			topLeft = center - semiDiagonal
> 			bottomRight = center + semiDiagonal
>                }
> 
> 		setUp  // execute the method
> 		method ...
> 		method ...
> 					...
> 	}


I don't like this approach, because it re-introduces all of the problems with object initialization that we solved when we invented object constructors.  Specifically, if setUp is a method, then initialization of this object can be broken by overriding setUp in a superObject.  Or can it?  
Well, that depends on whether we have different rules for method requests that occur before the requestor exists, which I suppose we must have, because your setUp method "assigns" to defined names ...  that's three more language constructs you just added.

(1) defs without values
(2) delayed binding of def'd names using =
(3) "methods" that can only be requested on self, and only before self has been created.  

Actually, setUp should be private (= lexically-bound), not confidential, and reading the Encapsulation paper again, I am inclined to think that we may need that.   If we don't have it, then this "pollutes the namespace" of methods, which is far worse than polluting that of fields, since methods are externally visible, and I don't think that (by default) fields should be.

	Andrew



More information about the Grace-core mailing list