From: Markus Armbruster <armbru@redhat.com>
To: "Andreas Färber" <afaerber@suse.de>
Cc: "peter.maydell@linaro.org" <peter.maydell@linaro.org>,
"peter.crosthwaite@xilinx.com" <peter.crosthwaite@xilinx.com>,
"Huangweidong (C)" <weidong.huang@huawei.com>,
"aliguori@amazon.com" <aliguori@amazon.com>,
"mst@redhat.com" <mst@redhat.com>,
"marcel.a@redhat.com" <marcel.a@redhat.com>,
Luonengjun <luonengjun@huawei.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"lcapitulino@redhat.com" <lcapitulino@redhat.com>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"av1474@comtv.ru" <av1474@comtv.ru>,
"kraxel@redhat.com" <kraxel@redhat.com>,
"stefanha@redhat.com" <stefanha@redhat.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"dmitry@daynix.com" <dmitry@daynix.com>,
"imammedo@redhat.com" <imammedo@redhat.com>,
"Huangpeng (Peter)" <peter.huangpeng@huawei.com>,
"dgilbert@redhat.com" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/8] usb: a trivial code change for more idiomatic writing style
Date: Fri, 01 Aug 2014 08:41:18 +0200 [thread overview]
Message-ID: <87fvhglnjl.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <53DB0CB1.9040207@suse.de> ("Andreas Färber"'s message of "Fri, 01 Aug 2014 05:42:41 +0200")
Andreas Färber <afaerber@suse.de> writes:
> Am 01.08.2014 05:32, schrieb Gonglei (Arei):
>> Hi,
>>
>>> Subject: Re: [PATCH v2 2/8] usb: a trivial code change for more
>>> idiomatic writing
>>> style
>>>
>>> On 07/31/2014 08:32 PM, arei.gonglei@huawei.com wrote:
>>>> From: Gonglei <arei.gonglei@huawei.com>
>>>>
>>>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>>>> ---
>>>> hw/usb/dev-audio.c | 2 +-
>>>> hw/usb/dev-mtp.c | 4 ++--
>>>> hw/usb/hcd-ehci.c | 2 +-
>>>> 3 files changed, 4 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
>>>> index bfebfe9..988f6cc 100644
>>>> --- a/hw/usb/dev-audio.c
>>>> +++ b/hw/usb/dev-audio.c
>>>> @@ -371,7 +371,7 @@ static void output_callback(void *opaque, int avail)
>>>> return;
>>>> }
>>>> data = streambuf_get(&s->out.buf);
>>>> - if (NULL == data) {
>>>> + if (data == NULL) {
>>>
>>> Wouldn't it be even more idiomatic as:
>>>
>>> if (!data) {
>>>
>>> Probably applies throughout your series.
>>>
>> OK, will do. Thanks!
>
> Not so quick! You are free to use that in your patches, but please don't
> change all code that way without the author's consent. Just like "equals
> null" is a natural English way of reading, compared to "null equals
> something", "not null" reads like a boolean expression to me, and even
> worse while all valid C, "not strcmp" leads to mind-boggling inverted
> logic...
!strcmp() is somewhat error prone, because it suggests inequality.
Can't claim that for !data. That one suggests "no data", which is
exactly right. Like Eric, I prefer it to the cumbersome data == NULL.
data == 0 is right out.
Since there's no consensus on !data vs. data == NULL, you're free to
follow your own taste in new code. When changing existing code, imitate
nearby code. When nearby code is inconsistent, it's your own taste
again.
next prev parent reply other threads:[~2014-08-01 6:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-01 2:32 [Qemu-devel] [PATCH v2 for-2.2 0/8] about Yoda conditions arei.gonglei
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 1/8] CODING_STYLE: Section about conditional statement arei.gonglei
2014-08-01 3:07 ` Eric Blake
2014-08-01 3:31 ` Gonglei (Arei)
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 2/8] usb: a trivial code change for more idiomatic writing style arei.gonglei
2014-08-01 3:08 ` Eric Blake
2014-08-01 3:32 ` Gonglei (Arei)
2014-08-01 3:42 ` Andreas Färber
2014-08-01 3:54 ` Gonglei (Arei)
2014-08-01 6:41 ` Markus Armbruster [this message]
2014-08-01 6:50 ` Gonglei (Arei)
2014-08-01 15:56 ` Eric Blake
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 3/8] audio: " arei.gonglei
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 4/8] isa-bus: " arei.gonglei
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 5/8] " arei.gonglei
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 6/8] spice: " arei.gonglei
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 7/8] vl: " arei.gonglei
2014-08-01 2:32 ` [Qemu-devel] [PATCH v2 8/8] vmxnet3: " arei.gonglei
2014-08-01 2:51 ` [Qemu-devel] [PATCH v2 for-2.2 0/8] about Yoda conditions Eric Blake
2014-08-01 3:23 ` Gonglei (Arei)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fvhglnjl.fsf@blackfin.pond.sub.org \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=arei.gonglei@huawei.com \
--cc=av1474@comtv.ru \
--cc=dgilbert@redhat.com \
--cc=dmitry@daynix.com \
--cc=imammedo@redhat.com \
--cc=kraxel@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=luonengjun@huawei.com \
--cc=marcel.a@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.huangpeng@huawei.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=weidong.huang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.