[webkit-dev] strcmp result checking

Darin Adler darin at apple.com
Thu Dec 17 10:23:10 PST 2009


My preference is:

    1) I prefer functions that return booleans over more complex things like strcmp-style return values. The name of the function ends up being much clearer in an if statement. Hence, I would like to see a simple cover with a better name when checking for equality rather than using strcmp directly.

    2) When using strcmp for a particular check (==, <, >, <=, >=), I prefer to use comparison with 0 on the right side of the strcmp expression so you can see the specific operator involved.

    Thus to check if a < b, I prefer:

        strcmp(a, b) < 0

    And to check if a == b, I prefer:

        strcmp(a, b) == 0

    And so on. The fact that the relational operator is there in the expression makes it much easier to read than an expression without one.

If we can work out the details I would love having something in the guidelines that suggested either (1) or (2) or both.

    -- Darin


More information about the webkit-dev mailing list