On Thu, Oct 03, 2002 at 05:23:08PM -0500, Jonathan Scott Duff wrote:
> I don't know, but I think it's supposed to be like this:
> 
>       # part of the signature
>       method turn($dir,$ang) is pre { $ang <= 20 } {
>       ...
>       }
> 
>       # part of the implementation
>       method turn($dir,$ang) {
>           PRE { $ang <= 20 }
>           ...
>       }
> 
> turn() methods of derived classes would inherit the precondition in the
> first case but not the second. I don't know why you'd want to do this
> exactly, but it seems to me that perl should allow it.

I see us already smashing too many things into the method signature as it
is.  It will rapidly get messy if you have a method with a complex signature
and a handful of attributes and preconditions.

Also, where do the postconditions go?  In the signature at the front?  That
doesn't make sense, it should go at the end so you can keep them in mind
when you're writing the return code.

Consider...

           method foo($this, $that) is memoized is something
                                    is pre { $this <= 42 }
                                    is pre { $that == $this / 2 }
                                    is pre { a lot of code which is hard to
                                             shove into a block of code
                                             this close to the right margin }
                                    is post { what is a post condition
                                              doing at the front? }
           {
               ...
           }

They can, of course, be pulled back from the margin:

           method foo($this, $that) is memoized is something
               is pre { $this <= 42 }
               is pre { $that == $this / 2 }
               is pre { now we have a little bit more room to play with using
                        a differnt indentation style }
               is post { but post conditions are still distanced from the
                         code which return()s }
           {
               ...
           }

I realize that conditions are technically part of the signature, but putting
them in there paints us into a stylistic corner.

I'm also not fond of the pre/PRE distinction.  Few of the other special
blocks (given, eval, try, invar, etc...) use all cap names.  At least I hope
not.  Simply attaching an "is private" attribute to a pre condition block
seems the simplest way to go about it.  Just like any other private thing,
it's not inherited and not visible outside the current class.  "pre" vs
"PRE" doesn't convey that meaning.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
AY!  The ground beef, she is burning my groin!
        http://sluggy.com/d/990105.html

Reply via email to