gnustep-dev
[Top][All Lists]
Advanced

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

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


From: Manuel Guesdon
Subject: Re[3]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?)
Date: Sat, 31 Jan 2004 01:16:12 +0100 (CET)

On Fri, 30 Jan 2004 19:26:19 +0000 (GMT) Nicola Pero <address@hidden> wrote:

 >| 
 >| >  >| I don't have particular objections to change 'if ([this canDoThat] ==
 >| >  >| YES)' into 'if ([this canDoThat])', if we write clearly in the coding
 >| >  >| standards that this can be done only for methods returning a BOOL, and
 >| >  >| that everything else (pointers, integers, etc) must be compared 
 >against
 >| >  >| something.  So whenever you'd see 'if ([this doThat])' you know that 
 >the
 >| >  >| result type must have been a BOOL since it's compared to nothing.
 >| > 
 >| > I think that 
 >| >         if (MyPtr)
 >| > is more readable than
 >| >         if (MyPtr == NULL)
 >| > because it's shorter and still easily understandable buts it's only my 
 >opinion :-)
 >| 
 >| I see your point and I somewhat respect it, but I'd politely disagree with
 >| you.
 >| 
 >| Shorter code is not necessarily more readable.  Variables are often
 >| declared somewhere else, and variable names often don't help that much.  
 >| Not all pointers are called 'xxxPtr'.  For example,
 >| 
 >|  if (bytes)
 >|    {
 >|    }
 >| 
 >| is a typical example of obscure code.  What is 'bytes' ?  Is it an integer
 >| ?  A char * ?  an object ?

But why calling it bytes ? 


 >| I think I really prefer 
 >| 
 >|  if (bytes > 0)
 >|    {
 >|    }
 >| 
 >| then it's clear that bytes is a counter, and that is executed only if the 
 >| counter is positive.

Agree, but naming it bytesCount will be, IMHO, better :-)


 >|  if (bytes != NULL)
 >|    {
 >|    }
 >| 
 >| then it's clear that bytes is a C pointer, likely a C buffer, and the code
 >| is executed is the pointer points to something (which usually means you 
 >| can derefence it).

So we could name it buffer, bytesPtr or pStr


 >|   if (bytes != nil)
 >|     {
 >|     }
 >| 
 >| then it's clear that bytes is an ObjC object, likely an NSData * object,
 >| or maybe an NSString *, and the code is executed if the object is not nil
 >| (which usually means you can send messages to it).
 >| 
 >| Those cases are very different, and I like the code to immediately give a
 >| feeling of which case you're in - the code is more expressive and easier
 >| to read then.

You're right with these kind of name. I haven't thought of this kind of cases 
because I 
usually try to give explicit name.

Finally, I still prefer short notation but I understand your view, so ...

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]