On 7/25/22 03:31, Huang, Haibin wrote:
Hi Michal Peter,
Thank you for your comments.
Way 1:
virBufferAsprintf(buf, "<flc>%s</flc>\n", sgx->flc ?
"yes" : "no");
Way 2:
if (sgx->flc) {
virBufferAsprintf(buf, "<flc>yes</flc>\n");
} else {
virBufferAsprintf(buf, "<flc>yes</flc>\n");
}
For this section, both ways of writing work.
Peter Krempa said: "Don't use the ternary operator ('?'), use a full
if/else branch instead or pick a better data structure."
You mean to be more concise use the ternary operator ('?').
Yeah, this one should be exempt from our ternary operator rule. The idea
behin the rule is to avoid complicated (or even composed) expressions
with a ternary operator. However, this is not the case and in fact,
ternary operator makes the code more readable. And we already use this
pattern for formatting other booleans, indeed.
We may switch to virTristateBool but one can argue that FLC is not
really tristate, it's either present or not; there's no _ABSENT state.
On the other hand, we may assign _ABSENT special meaning - the structure
was just allocated and does not hold decisive answer for FLC presence.
So let me switch to virTristateBool.
BTW: I've discussed with Yang that I'll fix up these patches and resend.
Is that agreement still on?
Michal