[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190111033607.rsuj3yii6yoiksqm@raspberrypi>
Date: Fri, 11 Jan 2019 03:36:07 +0000
From: Sidong Yang <realwakka@...il.com>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] staging: vboxvideo: vbox_main: Remove unnecessary local
variable
On Thu, Jan 10, 2019 at 10:44:08PM +0300, Dan Carpenter wrote:
> On Thu, Jan 10, 2019 at 05:00:24PM +0000, Sidong Yang wrote:
> > I think you just point out that my code isn't obvious because the
> > function returns negative error codes. I agree with you. But what if
> > change my code like if(hgsmi_query_conf() != 0).
> >
>
> That's even worse! :P
>
> You should do comparisons with zero when you are talking about zero
> meaning the number zero. In this case, hgsmi_query_conf() returns "zezro
> meaning success" not "zero meaning the number zero". How many bytes?
> Zero. That is the number zero.
>
> != zero is a double negative, because NOT and ZERO are negatives. If
> double negatives simplified the code we would add four of them instead
> of just the one:
>
> if ((((hgsmi_query_conf() != 0) != 0) != 0) != 0) {
>
> See? Adding != 0 doesn't make it simpler...
>
> The other place where != 0 is appropriate besides talking about the
> number is when you're using a strcmp() function because it works like
> this:
>
> if (strcmp(a, b) < 0) { <-- means a < b
> if (strcmp(a, b) == 0) { <-- means a == b
> if (strcmp(a, b) != 0) { <-- means a != b
>
> regards,
> dan carpenter
>
You're right. that is even worse. I understand and thank you for pointing out.
regards,
Sidong Yang
Powered by blists - more mailing lists