Re: [PATCH] staging: vboxvideo: vbox_main: Remove unnecessary local variable
From: Dan Carpenter
Date: Thu Jan 10 2019 - 14:44:17 EST
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