[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r25554 - trunk/subversion/libsvn_wc

From: C. Michael Pilato <cmpilato_at_collab.net>
Date: 2007-06-27 17:50:11 CEST

Paul Burba wrote:
> Heh, ok, I admit it, I'm in love with the ternary operator. But if
> there is anything even approaching general agreement that the above
> examples hinder code readability, I'm more than happy to use something
> like this from now on:
>
> if (strcmp(parent_child_url, entry->url))
> *switched = TRUE;
> else
> *switched = FALSE;
>
> Hopefully this is not a bikedshed issue!

There is a bit of a convention in the Subversion codebase (or at least there
was at one time) of always explicitly testing the return value from
strcmp()). Because a "true" return from strcmp actually means, the strings
*don't* compare, we use comparisons with 0 so that '==' and '!=' map to
"strings are equal" and "strings aren't equal", respectively.

I, too, love the ternary operation. So I'd suggest one of these two,
depending on the result of the call on whether we have to explicitly use
FALSE and TRUE values:

   *switched = (strcmp(parent_child_url, entry->url) != 0);
   *switched = (strcmp(parent_child_url, entry->url) == 0) ? FALSE : TRUE;

-- 
C. Michael Pilato <cmpilato@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand

Received on Wed Jun 27 17:50:17 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.