[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBo
From: |
Helge Hess |
Subject: |
Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?) |
Date: |
Mon, 2 Feb 2004 02:18:34 +0100 |
On 30.01.2004, at 20:26, Nicola Pero wrote:
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,
Hm, well, we were talking about BOOL, right? But anyway ...
if (bytes)
{
}
is a typical example of obscure code. What is 'bytes' ? Is it an
integer
? A char * ? an object ?
I don't find it that obscure. Its a descriptive name, in which case
could a 'bytes' name imply an integer? That would be byteCount or
numberOfBytes or something like that, but 'bytes' is just that - an
array of bytes.
I think I really prefer
if (bytes > 0)
{
}
Thats obscure for me - but I somewhat agree, it should be
if (numberOfBytes > 0)
Why? Because numberOfBytes is not used as a boolean. We are *really*
doing a range comparison here and "if" checks a condition.
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).
Well, as mentioned before, I think that it should be clear from the
name that we are talking about an pointer - eg 'bytes' or 'buf' is
clearly a ptr or char array - if not, the bug is in the naming, not in
the check.
But I would also like to point out again that the above code has twice
the chance to break! Because you are doing two operations instead of
one:
a) bytes!=NULL
b) if(condition)
And in my experience that is not so unlikely. Eg you at least run into
the common problem of 'bytes = NULL', but also in additional variants.
if (bytes != nil)
then it's clear that bytes is an ObjC object
Anyone who names an object 'bytes' should be send in prison ;-) Its
'dataObject' or just 'data' ;-)
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.
Disagreed. The name should transport the intention of the code. If you
do a comparison, like 'a > 0', write down the comparison, if you check
for a condition, write down the condition-check 'if (a)'.
regards,
Helge
--
http://docs.opengroupware.org/Members/helge
OpenGroupware.org
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), (continued)
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Nicola Pero, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/03
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/03
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Richard Frith-Macdonald, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/02
Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/01
Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?),
Helge Hess <=
Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/01
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Leigh Smith, 2004/02/02
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Helge Hess, 2004/02/02
- Re: Re[2]: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Marco Scheurer, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), David Ayers, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool: ?), Pascal J . Bourguignon, 2004/02/02
- Re: [RFA]: BOOL coding standards (Was: Problem with +numberWithBool:?), Alexander Malmberg, 2004/02/03
Re: [RFA]: BOOL coding standards (Was: Problem with+numberWithBool: ?), Alexander Malmberg, 2004/02/02