discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setter Gettor method style


From: Pascal Bourguignon
Subject: Re: Setter Gettor method style
Date: Mon, 5 Aug 2002 00:55:30 +0200 (CEST)

> From: Martin =?iso-8859-1?Q?H=E4cker?= <mhaecker@mac.com>
> Date: Mon, 5 Aug 2002 00:09:57 +0200
> 
> >  > I am not completely sure of that, but as I understand it the Cocoa
> >>  Engineer (Ali Ozer) told this pattern because of the "Foundation
> >>  Contract" as he called it, that every object you get from the
> >>  foundation should be valid for the scope of the method it was got in.
> >
> >Why not, if only all these "Contracts" were documented somewhere...
> 
> That is exactly the reason why I asked here about which style is used 
> throughout GnuStep.
> 
> Do you use a "Contract" like this? Or is there some other Contract?

Given the general state  of software documentation, the primary source
for these "contracts" is the source, and folklore :-P.

Otherwise,  in the code  I write,  I put  comments with  the following
entries along with the method and function definitions:

    -(void)sampleMethod:(type)parameter
                /*
                        PRE:            pre-condition
                        POST:           post-condition
                        DO:                     description of the method in 
English 
                        RETURN:         the result returned.
                        WARNING:        a warning.
                        NOTE:           a note.
                        parameter:      description of the parameter 
`parameter'.
                */      

For example:

    -(id)initWithContext:(O2CI7Context*)aContext;
        /*
            NOTE:       This is the designated initialized.
            aContext:   is the O2CI7 connection that created this cursor.
            PRE:        [aContext retainCount]==n
            POST:       [aContext retainCount]==n+1
        */

Unfortunately,  we   don't  always  write   full  pre/post  conditions
formally. And I only know of  Eiffel to actually process and check the
PRE and  POST conditions;  well, in Objective-C,  we could  always add
NSAssert()s  at the  beginning  and at  the  end, but  you don't  have
available the full  mathematical language you can use  in the pre/post
conditions.

> Sorry, I don't want to bore you with these questions.
> 
> One should also note that not all Cocoa classes from Apple currently 
> use this feature. Some because they decided they should not 
> (Collection classes) and others because at the time they where 
> written they still where not sure which pattern would be the best, 
> yet he also stated that Apple is slowly changing this as long as they 
> don't introduce binary incompatibility with this.
> 
> Peace,
> Martin


-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]