Re: [PATCH v2 0/3] C99: declare bool experiment a success
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 15, 2025, 22:09 UTC
- Message-ID
- <xmqqikjtf6nu.fsf@gitster.g>
- In-Reply-To
- <aHbMlUKNL2CAK_9I@fruit.crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> This series looked good to me. I especially like the fact that we've > made it easier for me to figure out whether starts_with and friends are > booleans (that is, true if it starts with the value) or our standard > zero/negative-one (that is, false if it starts with the value).
Hmph, this is a tangent, I've never thought of it that way.
The "0 is success and negative is failure" is exactly about success and failure. We expect such a call to succeed most of the time and failure is a note-worthy event.
Functions like starts_with() and friends, those that Lispers might name with q suffix, are quite different. A predicate is asking "is it, or isn't it?" question and returning "false" from it does not imply a failure in any way.
I wouldn't dream of making them return -1 for "failure", because starts_with(buf.buf, "#") that finds buf.buf does not begin with "#" is no way failing.
Anyway, we may start rewriting our old-fashioned idiom to normalize a "true if non-zero" integers, i.e.
return !!some_true_if_non_zero_integer_variable;
into
return (bool)some_true_if_non_zero_integer_variable;
perhaps ;-).