gnustep-dev
[Top][All Lists]
Advanced

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

Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool:


From: Manuel Guesdon
Subject: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?)
Date: Sat, 31 Jan 2004 13:55:05 +0100 (CET)

On Sat, 31 Jan 2004 12:44:50 +0800 Sheldon Gill <address@hidden> wrote:
[...]
I
 >| So, within GNUstep code I think the _right_ thing to do is precisely 
 >Richard's 
 >| recommendation of
 >| 
 >| isYES(x): IF  x NOT IN {YES|NO} THEN raise
 >| 
 >| which we can use to test all "+/- (BOOL)aMethod".  Any method which returns 
 >| something other than {YES|NO} is bad practice we should catch and eliminate.
 >| Any method which is defined to return one of these two values but actually 
 >can 
 >| return additional values is out of specification and should be corrected.

One of the problem is:

-(NSNumber*)numberWithBool:(BOOL)value
{
        if (value==YES)
                return YesNumber;
        else if (value==NO)
                return NoNumber;
        else
                raise...
}

 [NSNumber numberWithBool:isupper(SomeChar)] will/may raise as "The  values  
returned  are  nonzero  if  the character c falls into the
       tested class, and a zero value if not."
and BOOL type is a char.

OK, we can write  [NSNumber numberWithBool:(isupper(SomeChar) ? YES : NO)]
but it's not the first thing I'll write (I'll begin with: [NSNumber 
numberWithBool:isupper(SomeChar)])  so I'll
get sooner or later an exception, may be not reproductible. 

Now, if BOOL is a real BOOL (i.e. it will transform all non zero value to 1), 
it's OK but in this case, there's no need
to handle not (0|1) case as it never occur....


Manuel

-- 
______________________________________________________________________
Manuel Guesdon - OXYMIUM <address@hidden>
14 rue Jean-Baptiste Clement  -  93200 Saint-Denis  -  France
Tel: +33 1 4940 0999  -  Fax: +33 1 4940 0998





reply via email to

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