git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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 ;-).
Previous: brian m. carlsonNext: Phillip Wood
Message 24 of 33 in “C99: declare bool experiment a success”
  1. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 14, 2025
  2. 1/3 CodingGuildlines: allow the use of boolPhillip Wood, Jul 14, 2025
  3. Junio C HamanoJul 14, 2025
  4. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 14, 2025
  5. Eric SunshineJul 14, 2025
  6. Elijah NewrenJul 14, 2025
  7. brian m. carlsonJul 14, 2025
  8. Phillip WoodJul 15, 2025
  9. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 14, 2025
  10. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 15, 2025
  11. 1/3 CodingGuildlines: allow the use of boolPhillip Wood, Jul 15, 2025
  12. Jeff KingJul 16, 2025
  13. Jeff KingJul 16, 2025
  14. Elijah NewrenJul 16, 2025
  15. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 15, 2025
  16. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 15, 2025
  17. Elijah NewrenJul 15, 2025
  18. rsbecker@nexbridge.comJul 15, 2025
  19. Elijah NewrenJul 15, 2025
  20. rsbecker@nexbridge.comJul 15, 2025
  21. Junio C HamanoJul 15, 2025
  22. Junio C HamanoJul 15, 2025
  23. brian m. carlsonJul 15, 2025
  24. Junio C HamanoJul 15, 2025
  25. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 16, 2025
  26. 1/3 CodingGuidelines: allow the use of boolPhillip Wood, Jul 16, 2025
  27. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 16, 2025
  28. Karthik NayakJul 16, 2025
  29. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 16, 2025
  30. Karthik NayakJul 16, 2025
  31. Karthik NayakJul 16, 2025
  32. Phillip WoodJul 17, 2025
  33. Karthik NayakJul 22, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.