[haiku-commits] Re: haiku: hrev49006 - src/apps/showimage

  • From: CodeVisio <codevisio@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 08 Apr 2015 13:09:26 +0200


On 4/8/2015 11:57 AM, Axel Dörfler wrote:

Am 07.04.2015 um 22:03 schrieb Ingo Weinhold:
On 04/07/2015 09:55 PM, Axel Dörfler wrote:
Am 07/04/2015 um 18:17 schrieb janus2@xxxxxxxxx:
+ if (thread == B_NAME_NOT_FOUND)
+ break;

As I wrote in the comments, please never check for a specific error,
instead just use:
if (thread != B_OK)

Or a version that also works:
if (thread < 0)

:-)

Oops :-)
Thanks!

Bye,
Axel.


Hallo,

my name is Roberto and I'm new here. Although I've subscribed myself on
this list since a while, I haven't participated on the Haiku's code or
on the discussions. So I'm completely new.

Never the less, I'd like to give my opinion on the discussion above. If
that isn't appropriate or I'm not allowed to do this then pls discard my
contribution. It would be OK as well, but let me know that! so I'll
avoid to interrupt you again :).

My contribution is related only to the if-expression above and to have
it clearer.

Assuming:
- the range of possible values for a thread's ID are well established
- 'thread' variable could take one of those thread's ID values or
invalid ones (or undefined)

then

I'd use an if-expression like so:

if( thread < THREAD_ID_MIN_VALUE )
{
...
}

where THREAD_ID_MIN_VALUE is defined as:

#define THREAD_ID_BASE 0
#define THREAD_ID_MIN_VALUE THREAD_ID_BASE


Obv. the name of the constants could be better defined following Haiku's
code guidelines. But I'd use a constant to check the 'thread' variable
against to, because that would give an immediate meaning (semantic) to
the user of what the if-expression is all about.

On the contrary, leaving the if-expression as it is, where the variable
'thread' is checked against 0 (with the operator '<'), doesn't give an
immediate explanation to the user of what is going on, except that a an
integer or long or whatever is compared against 0. And to have a clue
about the code, the user needs to go back in the code looking for the
last assignment that has be done to the 'thread' variable.

I hope all of you don't mind about my suggestion while hoping it will be
useful in some way.

-- Roberto

Other related posts: