Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: Read errors

Re: Read errors

From: Mike Holden <rockbox_at_mikeholden.uklinux.net>
Date: Thu, 13 Mar 2003 21:36:36 -0000 (GMT)

Linus Nielsen Feltzing said:
> Mike Holden wrote:
>> Maybe a better construct would be to define 2 macros, called success()
>> and failure() which do a bit of hidden "magic" to make the code more
>> readable.
>
> Absolutely not! That kind of "hidden magic" is against everything my
> coding philosophy stands for. I want things visible in the code. Keep It
> Simple Stupid.
>
Fair enough! Reasonable comment.

>> That way you can write "if (success(somefunction()))", which is way
>> more readable than "if(somefunction())" where somefunction() returns 0
>> for success.
>
> I don't agree. I think the latter is way more readable, because it shows
> what is going on, instead of hiding it in a hard-to-debug macro.
>

The other option, where the function does not return a boolean, is to make
this more obvious in the if statement, so the above becomes "if (0 !=
somefunction())", which makes the whole thing readable without hidden
macros, and also makes it obvious to the reader of the code that
somefunction() doesn't return a boolean, but an integer instead. That way
it helps the reader who is not intimately familiar with the code, who may
not know (without checking the source for it) that somefunction() returns
0 for success.

> A simple comment may be in place, however.

Indeed. A well placed comment can make a world of difference, especially
when unfamiliar with the code.
Received on 2003-03-13

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy