On 4/22/25 11:24, Markus Armbruster wrote:
Effectively duplicates generated enum SysEmuTarget. Can you explain why
that's useful?
In terms of code, it doesn't change anything. we could reuse SysEmuTarget.
I just think it's more clear to have the enum defined next to the structure
using it, compared to have this buried in generated code that can't be grepped
easily.
(git grep SYS_EMU returns nothing, so people have to remember it's converted
from a Json, and that naming is different).
Yes, that's unfortunate, but we don't duplicate other QAPI enums because
of it.
Fine for me if it's the consensus we already have in QEMU, no one
mentioned it until your answer.
IMHO, DRY principle should not always be followed blindly when it hurts code
readability.
Treating DRY as dogma would be foolish.
I agree, alas, it tends to be treated as such, even unintentionally,
when people spend too much time on the same code/file.
That said, my editor is able to find the generated definition as well, so I
don't really mind reusing SysEmuTarget if we think the code readability is not
worth the duplication.
It's not just the duplication, it's also the conversion between the two
enums.
However, I think it's a problem to compare strings to find this, when it can be
set at compile time, in a file that will have to stay target specific anyway.
Converting from string to enum at first practical opportunity makes the
code simpler more often than not.
Sure, it's not what is done in the v4 anymore, so it's fine.
[...]