2008/2/17 Troy Curtis Jr <troycurtisjr_at_gmail.com>:
> On Feb 17, 2008 7:52 AM, Branko Čibej <brane_at_xbc.nu> wrote:
> > Troy Curtis Jr wrote:
> >
> > > +svn_boolean_t
> > > +svn_path_is_relative_url(const char *url)
> > > +{
> > > + return(0 == strncmp("^/", url, 2) ? TRUE : FALSE);
> > > +}
> > =-O
> >
> > I find this to be most inelegant.
> >
> > return !strncmp("^/", url, 2);
> >
> > -- Brane
> >
>
> Yeah but that is not the right return type now is it?
Sure it is. We don't make any pretenses that TRUE and FALSE are
anything but 1 and 0. ! returns a perfectly fine svn_boolean_t.
> And the return
> type was chosen based on precedence (svn_path_is_url()).
It's the right return type, and yes, svn_path_is_url does do a "? TRUE
: FALSE" thing, but that's because it's converting from const char *
to boolean.
> But even without that I am a big believer in being explicit for
> readability. You look at my line of code and you don't have to pause
> and make sure you have your inversions right, it is plainly obviously
> what it is doing. Of course there are a LOT more characters doing it
> my way, and that does bother some people. :)
>
> Of course even in my line the "0 ==" could be considered extraneous, I
> could leave it off and flip the TRUE and FALSE. But this way I really
> think it makes it much easier to see what the intention of the code
> is.
I think you don't have to think about your inversion if you just have
fewer operators, like in Brane's "!strcmp" example.
I mean, I wish that the standard C string-equality function was called
string_equal or something where the name obviously indicated the
return value, but it's not, so people do just learn that "!strcmp" or
"strcmp == 0" means "equals". "0 == strncmp ? TRUE : FALSE" is *not*
what people are used to seeing. It makes me actually thinking instead
of just saying "I know what that idiom means".
> To each his own right?
Sure, but consistency with the rest of the code base leads to fewer surprises.
--dave
--
David Glasser | glasser@davidglasser.net | http://www.davidglasser.net/
Received on 2008-02-17 22:15:29 CET