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

Re: [PATCH v2 06/10] diff-delta: explicitly mark intentional use of the comma operator

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Mar 26, 2025, 10:17 UTC
Message-ID
<ad57203b-8925-4f88-add6-763c2d80afac@gmail.com>
In-Reply-To
<050f5d65-32eb-fd26-1461-579b06018dc6@gmx.de>
Hi Johannes
On 26/03/2025 07:20, Johannes Schindelin wrote:
Show 28 quoted lines
> Hi Patrick,
> On Wed, 26 Mar 2025, Patrick Steinhardt wrote:
>> Hm. I think the end result is even more confusing than before. Why don't
>> we introduce curly braces here, same as in preceding commits?
> 
> The interleaved -/+ lines make it admittedly hard to see what I meant.
> I'll unwind it a bit (presenting only the `moff` part, the same
> consideration applies to `msize`):
> 
> 		if (moff & 0x000000ff)
> 			(void)(out[outpos++] = moff >> 0),  i |= 0x01;
> 		if (moff & 0x0000ff00)
> 			(void)(out[outpos++] = moff >> 8),  i |= 0x02;
> 		if (moff & 0x00ff0000)
> 			(void)(out[outpos++] = moff >> 16), i |= 0x04;
> 		if (moff & 0xff000000)
> 			(void)(out[outpos++] = moff >> 24), i |= 0x08;
> 
> In this form, it is very obvious (from comparing the right-side half of
> the lines) that a shifted version of `moff` is appended to `out` and `i`
> gets a bit set, and the correlation between shift width and the set bit
> is relatively easy to see and validate (at least my brain has an easy time
> here, thanks to the alignment and thanks to visual similarity between the
> non-blank parts).
> 
> It is admittedly quite a bit harder not to be distracted by the repetitive
> `(void)(out[...` parts to understand and validate the `if` conditions on
> the left-hand side,

That makes it pretty unreadable for me. If you're worried about the vertical space we could perhaps keep both statements on a single line so that we're only adding a single newline for the closing brace rather than two.

Best Wishes
Phillip
  but thanks to those repetitive parts being identical,
Show 35 quoted lines
> and being only one line between those `if` lines, I can bring my brain to
> focus only on the differences of the bitmask and understand and verify
> them with relatively little effort.
> 
> When I compared this form to the following, the cognitive load to wrap my
> head around the code is quite a bit higher there:
> 
> 		if (moff & 0x000000ff) {
> 			out[outpos++] = moff >> 0;
> 			i |= 0x01;
> 		}
> 		if (moff & 0x0000ff00) {
> 			out[outpos++] = moff >> 8;
> 			i |= 0x02;
> 		}
> 		if (moff & 0x00ff0000) {
> 			out[outpos++] = moff >> 16;
> 			i |= 0x04;
> 		}
> 		if (moff & 0xff000000) {
> 			out[outpos++] = moff >> 24;
> 			i |= 0x08;
> 		}
> 
> The reason is the visual distance between the near-identical code.
> 
> Having said that, I do realize that my brain quite possibly works in
> special ways here and that the general preference is to go with the latter
> form.
> 
> Do you have a strong opinion which form to use?
> 
> Ciao,
> Johannes
> 
Previous: Johannes SchindelinNext: Taylor Blau
Message 26 of 64 in “Avoid the comma operator”
  1. 0/2 Avoid the comma operatorJohannes Schindelin via GitGitGadget, Mar 25, 2025
  2. 1/2 remote-curl: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  3. Phillip WoodMar 25, 2025
  4. Jeff KingMar 25, 2025
  5. 2/2 rebase: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  6. Phillip WoodMar 25, 2025
  7. Philip OakleyMar 25, 2025
  8. Johannes SchindelinMar 25, 2025
  9. Taylor BlauMar 26, 2025
  10. Patrick SteinhardtMar 25, 2025
  11. Johannes SchindelinMar 25, 2025
  12. Taylor BlauMar 26, 2025
  13. Karthik NayakMar 25, 2025
  14. Junio C HamanoMar 25, 2025
  15. 00/10 Avoid the comma operatorJohannes Schindelin via GitGitGadget, Mar 25, 2025
  16. 01/10 remote-curl: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  17. 02/10 rebase: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  18. 03/10 kwset: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  19. 04/10 clar: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  20. Patrick SteinhardtMar 26, 2025
  21. Johannes SchindelinMar 26, 2025
  22. 05/10 xdiff: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 25, 2025
  23. 06/10 diff-delta: explicitly mark intentional use of the comma operatorJohannes Schindelin via GitGitGadget, Mar 25, 2025
  24. Patrick SteinhardtMar 26, 2025
  25. Johannes SchindelinMar 26, 2025
  26. Phillip WoodMar 26, 2025
  27. Taylor BlauMar 26, 2025
  28. Chris TorekMar 27, 2025
  29. 07/10 wildmatch: explicitly mark intentional use of the comma operatorJohannes Schindelin via GitGitGadget, Mar 25, 2025
  30. Patrick SteinhardtMar 26, 2025
  31. Johannes SchindelinMar 26, 2025
  32. Junio C HamanoMar 26, 2025
  33. Phillip WoodMar 26, 2025
  34. Junio C HamanoMar 26, 2025
  35. 08/10 compat/regex: explicitly mark intentional use of the comma operatorJohannes Schindelin via GitGitGadget, Mar 25, 2025
  36. Taylor BlauMar 26, 2025
  37. Johannes SchindelinMar 27, 2025
  38. Taylor BlauMar 27, 2025
  39. 09/10 clang: warn when the comma operator is usedJohannes Schindelin via GitGitGadget, Mar 25, 2025
  40. Patrick SteinhardtMar 26, 2025
  41. Johannes SchindelinMar 26, 2025
  42. Patrick SteinhardtMar 26, 2025
  43. Johannes SchindelinMar 27, 2025
  44. 10/10 detect-compiler: detect clang even if it found CUDAJohannes Schindelin via GitGitGadget, Mar 25, 2025
  45. Jeff KingMar 26, 2025
  46. Eric SunshineMar 26, 2025
  47. Jeff KingMar 27, 2025
  48. Eric SunshineMar 27, 2025
  49. Jeff KingMar 27, 2025
  50. Patrick SteinhardtMar 26, 2025
  51. Jeff KingMar 26, 2025
  52. 00/10 Avoid the comma operatorJohannes Schindelin via GitGitGadget, Mar 27, 2025
  53. 02/10 rebase: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 27, 2025
  54. 01/10 remote-curl: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 27, 2025
  55. 03/10 kwset: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 27, 2025
  56. 04/10 clar: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 27, 2025
  57. 05/10 xdiff: avoid using the comma operator unnecessarilyJohannes Schindelin via GitGitGadget, Mar 27, 2025
  58. 06/10 diff-delta: avoid using the comma operatorJohannes Schindelin via GitGitGadget, Mar 27, 2025
  59. 07/10 wildmatch: avoid using of the comma operatorJohannes Schindelin via GitGitGadget, Mar 27, 2025
  60. 08/10 compat/regex: explicitly mark intentional use of the comma operatorJohannes Schindelin via GitGitGadget, Mar 27, 2025
  61. 09/10 clang: warn when the comma operator is usedJohannes Schindelin via GitGitGadget, Mar 27, 2025
  62. 10/10 detect-compiler: detect clang even if it found CUDAJohannes Schindelin via GitGitGadget, Mar 27, 2025
  63. Phillip WoodMar 27, 2025
  64. Junio C HamanoMar 29, 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.