Re: [PATCH v2 2/6] unit-tests: add for_test
- From
René Scharfe <l.s.r@web.de>
- Date
- Jul 23, 2024, 12:37 UTC
- Message-ID
- <789d99ab-8d39-4f5f-a800-6ed5dd19d23e@web.de>
- In-Reply-To
- <CAO_smViM7_Er4hY_WvxJf_xWGtKVN29gJA9APzW3t3GdAaxsgQ@mail.gmail.com>
Am 23.07.24 um 00:47 schrieb Kyle Lippincott:
Show 8 quoted lines
> > If we have a good set of protections against misuse, does this mean > we're free to rename it? :) The concern raised for why `for` had to be > in the name was because it was using a control statement (a > at-most-1-execution for loop) to achieve its magic, and the control > statement puts certain restrictions and obligations on how to use it > correctly. If the misuse is detected reliably, we can choose a name > that's more descriptive about what it's doing.
Well, I called it "test" initially because I'm lazy and it describes its purpose.
But the fact remains that this is an iteration statement, even though it kinda looks like a function, and it should be used as such. We have to explicitly tell clang-format, and having "for" in the name reminds developers as well.
There is a slight dissonance between it executing at most once and it being an iteration. In C we commonly use conditionals ("if") for that. Calling it "if_test" would be misleading with "for" under the hood, though, as you cannot have an "else" branch -- which we don't need anyway.
That said, iterating zero or one times is possible and understandable not too much of a stretch IMHO. I can understand that one needs a minute to get used to that new keyword, though.
René