apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@tuxteam.de
Subject Re: [PATCH] How to Use strcmp to Check for Equality Without Confusing Your Fellow Code, Or: Isn't There a Macro for That?
Date Wed, 20 Oct 2010 05:15:21 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Oct 19, 2010 at 06:36:08PM +0200, Malte S. Stretz wrote:
> Hi folks,
> 
> I recently started to hack on the Apache HTTPD codebase and immediately 
> stumbled upon one of my personal code smells:  The usage of strcmp and 
> friends and how strings are compared for equality.
> 
> I know it is hard to agree on which variant is best [...]

Just a personal data point from a newcomer and mostly lurker: my
preferences are, in that order:

  strcmp(...) == 0

  !strcmp(...)

  macro

(macro coming definitely last). My primary language has been C for many
years; therefore, the idiomatic !strcmp(...) is easy on my eyes, but
still I consider the comparison to zero more readable (and semantically
more significant, since it reminds me of the fact that I might want
to compare the strings lexicographically, then strcmp(...) < 0 makes
sense too).

I don't particularly like the macros because they are necessarily
project-specific (so PostgreSQL would have one, the Linux kernel another
and libxml2 yet another). This tends to create little impenetrable
kingdoms. It hurts most on projects like Apache, where integrating many
other libraries is day-to-day.

Sorry for being so frank. All disclaimers apply: YMMV, and don't forget
that my opinion should be taken with a weight of about 0.1 since I never
contributed to APR (yet).

Regards and thanks for the good work
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFMvnrpBcgs9XrR2kYRAkX9AJ9pP6l0MG8Pv69+ylkStuUNKqjWwACfSLsB
bIUEdpHD9DFLbiiqxq65ud8=
=3juf
-----END PGP SIGNATURE-----

Mime
View raw message