[cairo] cairo_status_to_string and why I don't like CAIRO_OK
Kristian Høgsberg
krh at bitplanet.net
Fri Jun 10 10:28:25 PDT 2005
Carl Worth wrote:
> On Thu, 09 Jun 2005 10:19:38 -0400, Owen Taylor wrote:
>
>>I don't think we should write this. If we are frequently writing
>>
>> if (status) {
>> }
>>
>>Then we should simply write
>>
>> if (!status) {
>> }
>>
>>They are both pretty unreadable until you learn the idiom.
>
>
> If both of these forms appear in the code, then there's no idiom to
> learn. The code is just plain hard to read.
>
> My take on this is that "if (status)" is shorthand for "if (status !=
> CAIRO_STATUS_SUCCESS)", and the only way that idiom is learnable is
> that there's only shorthand for the test in one sense, (which is also
> overwhelmingly more common in the implementation).
I don't remember if this has been suggested, but what about
#define CAIRO_ERROR(status) ((status) != CAIRO_STATUS_SUCCESS)
instead of CAIRO_OK()? I don't like CAIRO_OK much myself, because it
feels like just a different (shorter) name for CAIRO_STATUS_SUCCESS, and
having two names for the same concept is a bad idea. CAIRO_ERROR()
doesn't have that problem since it covers a range of status codes.
This looks pretty intuitive:
if (CAIRO_ERROR (status))
...
and this is only slightly confusing:
if (!CAIRO_ERROR (status))
...
Kristian
More information about the cairo
mailing list