[Grace-core] How to Program in Grace

Kim Bruce kim at cs.pomona.edu
Wed Nov 21 16:12:21 PST 2012


> 
> Now I don't know how to write this code in Grace.  "Copy and Paste inheritance" is not a good idea.  The best that I could come up with was
> 
> class assertion.trait -> Assertion {
>     method assert(bb: Boolean)description(str) is public {
>         if (! bb) 
>> 
> and then inheriting from the class constructor:
> 
> object {
>             inherits assertion.trait
>             def tests = list.new
> 
> But it gets worse!  I also had object constructers with multiple methods, which used to inherit some of those methods from super object constructors, while overriding one of them (the one that actually did the construction).  How should I write those?
> 
> 	Andrew
> 
I'm not sure why converting those to classes doesn't work as well.  Can you give a more concrete example?

It seems to me that we know all of this stuff works fine for classes (either written as classes or object constructors).  The difficulty is for objects.  The problem with those has to do with initialization code.  In fact if we had a class with only immutable features whose initialization does not depend on self, then we have no issues at all.  

Of course another solution is to include the assertionTrait object as an instance variable rather than inheriting from it.  As we all know, inheritance is overused in OO languages.  Depending on how you are planning on using the assertionTrait object, that might be the best model anyway.  Certainly if you are applying it, it seems to be.  If you are adding other assertion methods, then you definitely would want it to be inherited.  Then with the current mechanisms, making it a class seems the best solution.

We could go back and rethink object initialization or we could rethink whether we want inheritance from objects.  I must admit, I think of objects as stand-alone entities that would not be mucked with -- e.g. , extended with inheritance.  But that's just a reflection of my background and experience.  I think of them as completed entities, while classes are incomplete, waiting for some action to make them complete or extend them.

Kim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailhost.cecs.pdx.edu/mailman/private/grace-core/attachments/20121121/7fb133af/attachment.html>


More information about the Grace-core mailing list